4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2006 Blender Foundation
21 * All rights reserved.
23 * Contributors: Hos, Robert Wenzlaff.
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file blender/render/intern/source/shadeinput.c
39 #include "BLI_blenlib.h"
40 #include "BLI_utildefines.h"
42 #include "DNA_curve_types.h"
43 #include "DNA_group_types.h"
44 #include "DNA_lamp_types.h"
45 #include "DNA_meshdata_types.h"
46 #include "DNA_material_types.h"
48 #include "BKE_colortools.h"
53 #include "raycounter.h"
54 #include "renderpipeline.h"
55 #include "render_types.h"
56 #include "renderdatabase.h"
57 #include "rendercore.h"
62 #include "volumetric.h"
65 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
66 /* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
67 /* only to be used here in this file, it's for speed */
68 extern struct Render R;
69 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
72 #define VECADDISFAC(v1,v3,fac) {*(v1)+= *(v3)*(fac); *(v1+1)+= *(v3+1)*(fac); *(v1+2)+= *(v3+2)*(fac);}
76 /* Shade Sample order:
78 - shade_samples_fill_with_ps()
80 - shade_input_set_triangle() <- if prev sample-face is same, use shade_input_copy_triangle()
82 - shade_input_set_viewco() <- not for ray or bake
83 - shade_input_set_uv() <- not for ray or bake
84 - shade_input_set_normals()
87 - shade_samples_do_AO()
90 - shade_input_set_shade_texco()
91 - shade_samples_do_shade()
92 - OSA: distribute sample result with filter masking
96 /* initialise material variables in shadeinput,
97 * doing inverse gamma correction where applicable */
98 void shade_input_init_material(ShadeInput *shi)
100 /* note, keep this synced with render_types.h */
101 memcpy(&shi->r, &shi->mat->r, 23*sizeof(float));
102 shi->har= shi->mat->har;
105 /* also used as callback for nodes */
106 /* delivers a fully filled in ShadeResult, for all passes */
107 void shade_material_loop(ShadeInput *shi, ShadeResult *shr)
110 shade_lamp_loop(shi, shr); /* clears shr */
112 if(shi->translucency!=0.0f) {
114 float fac= shi->translucency;
116 shade_input_init_material(shi);
118 VECCOPY(shi->vn, shi->vno);
119 VECMUL(shi->vn, -1.0f);
120 VECMUL(shi->facenor, -1.0f);
121 shi->depth++; /* hack to get real shadow now */
122 shade_lamp_loop(shi, &shr_t);
125 /* a couple of passes */
126 VECADDISFAC(shr->combined, shr_t.combined, fac);
127 if(shi->passflag & SCE_PASS_SPEC)
128 VECADDISFAC(shr->spec, shr_t.spec, fac);
129 if(shi->passflag & SCE_PASS_DIFFUSE)
130 VECADDISFAC(shr->diff, shr_t.diff, fac);
131 if(shi->passflag & SCE_PASS_SHADOW)
132 VECADDISFAC(shr->shad, shr_t.shad, fac);
134 VECMUL(shi->vn, -1.0f);
135 VECMUL(shi->facenor, -1.0f);
138 /* depth >= 1 when ray-shading */
139 if(shi->depth==0 || shi->volume_depth > 0) {
140 if(R.r.mode & R_RAYTRACE) {
141 if(shi->ray_mirror!=0.0f || ((shi->mode & MA_TRANSP) && (shi->mode & MA_RAYTRANSP) && shr->alpha!=1.0f)) {
142 /* ray trace works on combined, but gives pass info */
146 /* disable adding of sky for raytransp */
147 if((shi->mode & MA_TRANSP) && (shi->mode & MA_RAYTRANSP))
148 if((shi->layflag & SCE_LAY_SKY) && (R.r.alphamode==R_ADDSKY))
152 if(R.r.mode & R_RAYTRACE) {
153 if (R.render_volumes_inside.first)
154 shade_volume_inside(shi, shr);
159 /* do a shade, finish up some passes, apply mist */
160 void shade_input_do_shade(ShadeInput *shi, ShadeResult *shr)
164 /* ------ main shading loop -------- */
166 memset(&shi->raycounter, 0, sizeof(shi->raycounter));
169 if(shi->mat->nodetree && shi->mat->use_nodes) {
170 ntreeShaderExecTree(shi->mat->nodetree, shi, shr);
173 /* copy all relevant material vars, note, keep this synced with render_types.h */
174 shade_input_init_material(shi);
176 if (shi->mat->material_type == MA_TYPE_VOLUME) {
177 if(R.r.mode & R_RAYTRACE) {
178 shade_volume_outside(shi, shr);
180 } else { /* MA_TYPE_SURFACE, MA_TYPE_WIRE */
181 shade_material_loop(shi, shr);
185 /* copy additional passes */
186 if(shi->passflag & (SCE_PASS_VECTOR|SCE_PASS_NORMAL)) {
187 QUATCOPY(shr->winspeed, shi->winspeed);
188 VECCOPY(shr->nor, shi->vn);
192 if((shi->passflag & SCE_PASS_MIST) || ((R.wrld.mode & WO_MIST) && (shi->mat->mode & MA_NOMIST)==0)) {
193 if(R.r.mode & R_ORTHO)
194 shr->mist= mistfactor(-shi->co[2], shi->co);
196 shr->mist= mistfactor(len_v3(shi->co), shi->co);
198 else shr->mist= 0.0f;
200 if((R.wrld.mode & WO_MIST) && (shi->mat->mode & MA_NOMIST)==0 ) {
205 /* add mist and premul color */
206 if(shr->alpha!=1.0f || alpha!=1.0f) {
207 float fac= alpha*(shr->alpha);
208 shr->combined[3]= fac;
210 if (shi->mat->material_type!= MA_TYPE_VOLUME)
211 mul_v3_fl(shr->combined, fac);
214 shr->combined[3]= 1.0f;
221 if(1 || shi->passflag & SCE_PASS_RAYHITS)
223 shr->rayhits[0] = (float)shi->raycounter.faces.test;
224 shr->rayhits[1] = (float)shi->raycounter.bb.hit;
225 shr->rayhits[2] = 0.0;
226 shr->rayhits[3] = 1.0;
229 RE_RC_MERGE(&re_rc_counter[shi->thread], &shi->raycounter);
232 /* **************************************************************************** */
234 /* **************************************************************************** */
237 void vlr_set_uv_indices(VlakRen *vlr, int *i1, int *i2, int *i3)
239 /* to prevent storing new tfaces or vcols, we check a split runtime */
243 /* 1---2 1---2 0 = orig face, 1 = new face */
245 /* Update vert nums to point to correct verts of original face */
246 if(vlr->flag & R_DIVIDE_24) {
247 if(vlr->flag & R_FACE_SPLIT) {
248 (*i1)++; (*i2)++; (*i3)++;
254 else if(vlr->flag & R_FACE_SPLIT) {
259 /* copy data from face to ShadeInput, general case */
260 /* indices 0 1 2 3 only */
261 void shade_input_set_triangle_i(ShadeInput *shi, ObjectInstanceRen *obi, VlakRen *vlr, short i1, short i2, short i3)
263 VertRen **vpp= &vlr->v1;
277 /* note, shi->mat is set in node shaders */
278 shi->mat= shi->mat_override?shi->mat_override:vlr->mat;
280 shi->osatex= (shi->mat->texco & TEXCO_OSA);
281 shi->mode= shi->mat->mode_l; /* or-ed result for all nodes */
283 /* facenormal copy, can get flipped */
285 RE_vlakren_get_normal(&R, obi, vlr, shi->facenor);
287 /* calculate vertexnormals */
288 if(vlr->flag & R_SMOOTH) {
289 VECCOPY(shi->n1, shi->v1->n);
290 VECCOPY(shi->n2, shi->v2->n);
291 VECCOPY(shi->n3, shi->v3->n);
293 if(obi->flag & R_TRANSFORMED) {
294 mul_m3_v3(obi->nmat, shi->n1); normalize_v3(shi->n1);
295 mul_m3_v3(obi->nmat, shi->n2); normalize_v3(shi->n2);
296 mul_m3_v3(obi->nmat, shi->n3); normalize_v3(shi->n3);
301 /* note, facenr declared volatile due to over-eager -O2 optimizations
302 * on cygwin (particularly -frerun-cse-after-loop)
305 /* copy data from face to ShadeInput, scanline case */
306 void shade_input_set_triangle(ShadeInput *shi, volatile int obi, volatile int facenr, int UNUSED(normal_flip))
309 shi->obi= &R.objectinstance[obi];
310 shi->obr= shi->obi->obr;
311 shi->facenr= (facenr-1) & RE_QUAD_MASK;
312 if( shi->facenr < shi->obr->totvlak ) {
313 VlakRen *vlr= RE_findOrAddVlak(shi->obr, shi->facenr);
315 if(facenr & RE_QUAD_OFFS)
316 shade_input_set_triangle_i(shi, shi->obi, vlr, 0, 2, 3);
318 shade_input_set_triangle_i(shi, shi->obi, vlr, 0, 1, 2);
321 shi->vlr= NULL; /* general signal we got sky */
324 shi->vlr= NULL; /* general signal we got sky */
327 /* full osa case: copy static info */
328 void shade_input_copy_triangle(ShadeInput *shi, ShadeInput *from)
330 /* not so nice, but works... warning is in RE_shader_ext.h */
331 memcpy(shi, from, sizeof(struct ShadeInputCopy));
334 /* copy data from strand to shadeinput */
335 void shade_input_set_strand(ShadeInput *shi, StrandRen *strand, StrandPoint *spoint)
337 /* note, shi->mat is set in node shaders */
338 shi->mat= shi->mat_override? shi->mat_override: strand->buffer->ma;
340 shi->osatex= (shi->mat->texco & TEXCO_OSA);
341 shi->mode= shi->mat->mode_l; /* or-ed result for all nodes */
343 /* shade_input_set_viewco equivalent */
344 VECCOPY(shi->co, spoint->co);
345 VECCOPY(shi->view, shi->co);
346 normalize_v3(shi->view);
348 shi->xs= (int)spoint->x;
349 shi->ys= (int)spoint->y;
351 if(shi->osatex || (R.r.mode & R_SHADOW)) {
352 VECCOPY(shi->dxco, spoint->dtco);
353 VECCOPY(shi->dyco, spoint->dsco);
356 /* dxview, dyview, not supported */
358 /* facenormal, simply viewco flipped */
359 VECCOPY(shi->facenor, spoint->nor);
361 /* shade_input_set_normals equivalent */
362 if(shi->mat->mode & MA_TANGENT_STR) {
363 VECCOPY(shi->vn, spoint->tan)
368 cross_v3_v3v3(cross, spoint->co, spoint->tan);
369 cross_v3_v3v3(shi->vn, cross, spoint->tan);
370 normalize_v3(shi->vn);
372 if(INPR(shi->vn, shi->view) < 0.0f)
376 VECCOPY(shi->vno, shi->vn);
379 void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert *svert, StrandPoint *spoint)
381 StrandBuffer *strandbuf= strand->buffer;
382 ObjectRen *obr= strandbuf->obr;
384 int mode= shi->mode; /* or-ed result for all nodes */
385 short texco= shi->mat->texco;
387 if((shi->mat->texco & TEXCO_REFL)) {
388 /* shi->dxview, shi->dyview, not supported */
391 if(shi->osatex && (texco & (TEXCO_NORM|TEXCO_REFL))) {
395 if(mode & (MA_TANGENT_V|MA_NORMAP_TANG)) {
396 VECCOPY(shi->tang, spoint->tan);
397 VECCOPY(shi->nmaptang, spoint->tan);
400 if(mode & MA_STR_SURFDIFF) {
401 float *surfnor= RE_strandren_get_surfnor(obr, strand, 0);
404 VECCOPY(shi->surfnor, surfnor)
406 VECCOPY(shi->surfnor, shi->vn)
408 if(shi->mat->strand_surfnor > 0.0f) {
410 for(sv=strand->vert; sv!=svert; sv++)
411 shi->surfdist+=len_v3v3(sv->co, (sv+1)->co);
412 shi->surfdist += spoint->t*len_v3v3(sv->co, (sv+1)->co);
416 if(R.r.mode & R_SPEED) {
419 speed= RE_strandren_get_winspeed(shi->obi, strand, 0);
421 QUATCOPY(shi->winspeed, speed)
423 shi->winspeed[0]= shi->winspeed[1]= shi->winspeed[2]= shi->winspeed[3]= 0.0f;
426 /* shade_input_set_shade_texco equivalent */
427 if(texco & NEED_UV) {
428 if(texco & TEXCO_ORCO) {
429 VECCOPY(shi->lo, strand->orco);
430 /* no shi->osatex, orco derivatives are zero */
433 if(texco & TEXCO_GLOB) {
434 VECCOPY(shi->gl, shi->co);
435 mul_m4_v3(R.viewinv, shi->gl);
438 VECCOPY(shi->dxgl, shi->dxco);
439 mul_mat3_m4_v3(R.viewinv, shi->dxgl);
440 VECCOPY(shi->dygl, shi->dyco);
441 mul_mat3_m4_v3(R.viewinv, shi->dygl);
445 if(texco & TEXCO_STRAND) {
446 shi->strandco= spoint->strandco;
449 shi->dxstrand= spoint->dtstrandco;
454 if((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE))) {
462 shi->actuv= obr->actmtface;
463 shi->actcol= obr->actmcol;
465 if(mode & (MA_VERTEXCOL|MA_VERTEXCOLP)) {
466 for (i=0; (mcol=RE_strandren_get_mcol(obr, strand, i, &name, 0)); i++) {
467 ShadeInputCol *scol= &shi->col[i];
468 char *cp= (char*)mcol;
473 scol->col[0]= cp[3]/255.0f;
474 scol->col[1]= cp[2]/255.0f;
475 scol->col[2]= cp[1]/255.0f;
476 scol->col[3]= cp[0]/255.0f;
480 shi->vcol[0]= shi->col[shi->actcol].col[0];
481 shi->vcol[1]= shi->col[shi->actcol].col[1];
482 shi->vcol[2]= shi->col[shi->actcol].col[2];
483 shi->vcol[3]= shi->col[shi->actcol].col[3];
493 for (i=0; (uv=RE_strandren_get_uv(obr, strand, i, &name, 0)); i++) {
494 ShadeInputUV *suv= &shi->uv[i];
499 if(strandbuf->overrideuv == i) {
501 suv->uv[1]= spoint->strandco;
505 suv->uv[0]= -1.0f + 2.0f*uv[0];
506 suv->uv[1]= -1.0f + 2.0f*uv[1];
507 suv->uv[2]= 0.0f; /* texture.c assumes there are 3 coords */
517 if((mode & MA_FACETEXTURE) && i==obr->actmtface) {
518 if((mode & (MA_VERTEXCOL|MA_VERTEXCOLP))==0) {
527 if(shi->totuv == 0) {
528 ShadeInputUV *suv= &shi->uv[0];
531 suv->uv[1]= spoint->strandco;
532 suv->uv[2]= 0.0f; /* texture.c assumes there are 3 coords */
534 if(mode & MA_FACETEXTURE) {
535 /* no tface? set at 1.0f */
545 if(texco & TEXCO_NORM) {
546 shi->orn[0]= -shi->vn[0];
547 shi->orn[1]= -shi->vn[1];
548 shi->orn[2]= -shi->vn[2];
551 if(texco & TEXCO_STRESS) {
555 if(texco & TEXCO_TANGENT) {
556 if((mode & MA_TANGENT_V)==0) {
557 /* just prevent surprises */
558 shi->tang[0]= shi->tang[1]= shi->tang[2]= 0.0f;
559 shi->nmaptang[0]= shi->nmaptang[1]= shi->nmaptang[2]= 0.0f;
564 /* this only avalailable for scanline renders */
566 if(texco & TEXCO_WINDOW) {
567 shi->winco[0]= -1.0f + 2.0f*spoint->x/(float)R.winx;
568 shi->winco[1]= -1.0f + 2.0f*spoint->y/(float)R.winy;
580 if(texco & TEXCO_STICKY) {
585 if (shi->do_manage) {
586 if(mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) {
587 srgb_to_linearrgb_v3_v3(shi->vcol, shi->vcol);
593 /* from scanline pixel coordinates to 3d coordinates, requires set_triangle */
594 void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float *view, float *dxyview, float *co, float *dxco, float *dyco)
596 /* returns not normalized, so is in viewplane coords */
597 calc_view_vector(view, x, y);
599 if(shi->mat->material_type == MA_TYPE_WIRE) {
600 /* wire cannot use normal for calculating shi->co, so
601 * we reconstruct the coordinate less accurate */
602 if(R.r.mode & R_ORTHO)
603 calc_renderco_ortho(co, x, y, z);
605 calc_renderco_zbuf(co, view, z);
608 /* for non-wire, intersect with the triangle to get the exact coord */
609 float fac, dface, v1[3];
611 VECCOPY(v1, shi->v1->co);
612 if(shi->obi->flag & R_TRANSFORMED)
613 mul_m4_v3(shi->obi->mat, v1);
615 dface= v1[0]*shi->facenor[0]+v1[1]*shi->facenor[1]+v1[2]*shi->facenor[2];
617 /* ortho viewplane cannot intersect using view vector originating in (0,0,0) */
618 if(R.r.mode & R_ORTHO) {
619 /* x and y 3d coordinate can be derived from pixel coord and winmat */
620 float fx= 2.0f/(R.winx*R.winmat[0][0]);
621 float fy= 2.0f/(R.winy*R.winmat[1][1]);
623 co[0]= (x - 0.5f*R.winx)*fx - R.winmat[3][0]/R.winmat[0][0];
624 co[1]= (y - 0.5f*R.winy)*fy - R.winmat[3][1]/R.winmat[1][1];
626 /* using a*x + b*y + c*z = d equation, (a b c) is normal */
627 if(shi->facenor[2]!=0.0f)
628 co[2]= (dface - shi->facenor[0]*co[0] - shi->facenor[1]*co[1])/shi->facenor[2];
635 if(shi->facenor[2]!=0.0f)
636 dxco[2]= -(shi->facenor[0]*fx)/shi->facenor[2];
642 if(shi->facenor[2]!=0.0f)
643 dyco[2]= -(shi->facenor[1]*fy)/shi->facenor[2];
648 if(co[2]!=0.0f) fac= 1.0f/co[2]; else fac= 0.0f;
649 dxyview[0]= -R.viewdx*fac;
650 dxyview[1]= -R.viewdy*fac;
657 div= shi->facenor[0]*view[0] + shi->facenor[1]*view[1] + shi->facenor[2]*view[2];
658 if (div!=0.0f) fac= dface/div;
665 /* pixel dx/dy for render coord */
667 float u= dface/(div - R.viewdx*shi->facenor[0]);
668 float v= dface/(div - R.viewdy*shi->facenor[1]);
670 dxco[0]= co[0]- (view[0]-R.viewdx)*u;
671 dxco[1]= co[1]- (view[1])*u;
672 dxco[2]= co[2]- (view[2])*u;
674 dyco[0]= co[0]- (view[0])*v;
675 dyco[1]= co[1]- (view[1]-R.viewdy)*v;
676 dyco[2]= co[2]- (view[2])*v;
679 if(fac!=0.0f) fac= 1.0f/fac;
680 dxyview[0]= -R.viewdx*fac;
681 dxyview[1]= -R.viewdy*fac;
687 /* set camera coords - for scanline, it's always 0.0,0.0,0.0 (render is in camera space)
688 * however for raytrace it can be different - the position of the last intersection */
689 shi->camera_co[0] = shi->camera_co[1] = shi->camera_co[2] = 0.0f;
691 /* cannot normalize earlier, code above needs it at viewplane level */
695 /* from scanline pixel coordinates to 3d coordinates, requires set_triangle */
696 void shade_input_set_viewco(ShadeInput *shi, float x, float y, float xs, float ys, float z)
698 float *dxyview= NULL, *dxco= NULL, *dyco= NULL;
700 /* currently in use for dithering (soft shadow), node preview, irregular shad */
704 /* original scanline coordinate without jitter */
709 /* check if we need derivatives */
710 if(shi->osatex || (R.r.mode & R_SHADOW)) {
714 if((shi->mat->texco & TEXCO_REFL))
715 dxyview= &shi->dxview;
718 shade_input_calc_viewco(shi, xs, ys, z, shi->view, dxyview, shi->co, dxco, dyco);
721 /* calculate U and V, for scanline (silly render face u and v are in range -1 to 0) */
722 void shade_input_set_uv(ShadeInput *shi)
724 VlakRen *vlr= shi->vlr;
726 if((vlr->flag & R_SMOOTH) || (shi->mat->texco & NEED_UV) || (shi->passflag & SCE_PASS_UV)) {
727 float v1[3], v2[3], v3[3];
729 VECCOPY(v1, shi->v1->co);
730 VECCOPY(v2, shi->v2->co);
731 VECCOPY(v3, shi->v3->co);
733 if(shi->obi->flag & R_TRANSFORMED) {
734 mul_m4_v3(shi->obi->mat, v1);
735 mul_m4_v3(shi->obi->mat, v2);
736 mul_m4_v3(shi->obi->mat, v3);
739 /* exception case for wire render of edge */
740 if(vlr->v2==vlr->v3) {
743 lend= len_v3v3(v2, v1);
744 lenc= len_v3v3(shi->co, v1);
750 shi->u= - (1.0f - lenc/lend);
762 /* most of this could become re-used for faces */
763 float detsh, t00, t10, t01, t11, xn, yn, zn;
766 /* find most stable axis to project */
767 xn= fabs(shi->facenor[0]);
768 yn= fabs(shi->facenor[1]);
769 zn= fabs(shi->facenor[2]);
771 if(zn>=xn && zn>=yn) { axis1= 0; axis2= 1; }
772 else if(yn>=xn && yn>=zn) { axis1= 0; axis2= 2; }
773 else { axis1= 1; axis2= 2; }
775 /* compute u,v and derivatives */
776 t00= v3[axis1]-v1[axis1]; t01= v3[axis2]-v1[axis2];
777 t10= v3[axis1]-v2[axis1]; t11= v3[axis2]-v2[axis2];
779 detsh= (t00*t11-t10*t01);
780 detsh= (detsh != 0.0f)? 1.0f/detsh: 0.0f;
781 t00*= detsh; t01*=detsh;
782 t10*=detsh; t11*=detsh;
784 shi->u= (shi->co[axis1]-v3[axis1])*t11-(shi->co[axis2]-v3[axis2])*t10;
785 shi->v= (shi->co[axis2]-v3[axis2])*t00-(shi->co[axis1]-v3[axis1])*t01;
787 shi->dx_u= shi->dxco[axis1]*t11- shi->dxco[axis2]*t10;
788 shi->dx_v= shi->dxco[axis2]*t00- shi->dxco[axis1]*t01;
789 shi->dy_u= shi->dyco[axis1]*t11- shi->dyco[axis2]*t10;
790 shi->dy_v= shi->dyco[axis2]*t00- shi->dyco[axis1]*t01;
793 /* u and v are in range -1 to 0, we allow a little bit extra but not too much, screws up speedvectors */
794 CLAMP(shi->u, -2.0f, 1.0f);
795 CLAMP(shi->v, -2.0f, 1.0f);
800 void shade_input_set_normals(ShadeInput *shi)
802 float u= shi->u, v= shi->v;
807 /* test flip normals to viewing direction */
808 if(!(shi->vlr->flag & R_TANGENT)) {
809 if(dot_v3v3(shi->facenor, shi->view) < 0.0f) {
810 negate_v3(shi->facenor);
815 /* calculate vertexnormals */
816 if(shi->vlr->flag & R_SMOOTH) {
817 float *n1= shi->n1, *n2= shi->n2, *n3= shi->n3;
819 if(shi->flippednor) {
825 shi->vn[0]= l*n3[0]-u*n1[0]-v*n2[0];
826 shi->vn[1]= l*n3[1]-u*n1[1]-v*n2[1];
827 shi->vn[2]= l*n3[2]-u*n1[2]-v*n2[2];
829 // use unnormalized normal (closer to games)
830 VECCOPY(shi->nmapnorm, shi->vn);
832 normalize_v3(shi->vn);
836 VECCOPY(shi->vn, shi->facenor);
837 VECCOPY(shi->nmapnorm, shi->vn);
841 VECCOPY(shi->vno, shi->vn);
843 /* flip normals to viewing direction */
844 if(!(shi->vlr->flag & R_TANGENT))
845 if(dot_v3v3(shi->facenor, shi->view) < 0.0f)
846 shade_input_flip_normals(shi);
849 /* XXX shi->flippednor messes up otherwise */
850 void shade_input_set_vertex_normals(ShadeInput *shi)
852 float u= shi->u, v= shi->v;
855 /* calculate vertexnormals */
856 if(shi->vlr->flag & R_SMOOTH) {
857 float *n1= shi->n1, *n2= shi->n2, *n3= shi->n3;
859 shi->vn[0]= l*n3[0]-u*n1[0]-v*n2[0];
860 shi->vn[1]= l*n3[1]-u*n1[1]-v*n2[1];
861 shi->vn[2]= l*n3[2]-u*n1[2]-v*n2[2];
863 // use unnormalized normal (closer to games)
864 VECCOPY(shi->nmapnorm, shi->vn);
866 normalize_v3(shi->vn);
870 VECCOPY(shi->vn, shi->facenor);
871 VECCOPY(shi->nmapnorm, shi->vn);
875 VECCOPY(shi->vno, shi->vn);
879 /* use by raytrace, sss, bake to flip into the right direction */
880 void shade_input_flip_normals(ShadeInput *shi)
882 shi->facenor[0]= -shi->facenor[0];
883 shi->facenor[1]= -shi->facenor[1];
884 shi->facenor[2]= -shi->facenor[2];
886 shi->vn[0]= -shi->vn[0];
887 shi->vn[1]= -shi->vn[1];
888 shi->vn[2]= -shi->vn[2];
890 shi->vno[0]= -shi->vno[0];
891 shi->vno[1]= -shi->vno[1];
892 shi->vno[2]= -shi->vno[2];
894 shi->nmapnorm[0] = -shi->nmapnorm[0];
895 shi->nmapnorm[1] = -shi->nmapnorm[1];
896 shi->nmapnorm[2] = -shi->nmapnorm[2];
898 shi->flippednor= !shi->flippednor;
901 void shade_input_set_shade_texco(ShadeInput *shi)
903 ObjectInstanceRen *obi= shi->obi;
904 ObjectRen *obr= shi->obr;
905 VertRen *v1= shi->v1, *v2= shi->v2, *v3= shi->v3;
906 float u= shi->u, v= shi->v;
907 float l= 1.0f+u+v, dl;
908 int mode= shi->mode; /* or-ed result for all nodes */
909 short texco= shi->mat->texco;
912 if(shi->vlr->flag & R_SMOOTH) {
914 if(shi->osatex && (texco & (TEXCO_NORM|TEXCO_REFL)) ) {
915 float *n1= shi->n1, *n2= shi->n2, *n3= shi->n3;
917 dl= shi->dx_u+shi->dx_v;
918 shi->dxno[0]= dl*n3[0]-shi->dx_u*n1[0]-shi->dx_v*n2[0];
919 shi->dxno[1]= dl*n3[1]-shi->dx_u*n1[1]-shi->dx_v*n2[1];
920 shi->dxno[2]= dl*n3[2]-shi->dx_u*n1[2]-shi->dx_v*n2[2];
921 dl= shi->dy_u+shi->dy_v;
922 shi->dyno[0]= dl*n3[0]-shi->dy_u*n1[0]-shi->dy_v*n2[0];
923 shi->dyno[1]= dl*n3[1]-shi->dy_u*n1[1]-shi->dy_v*n2[1];
924 shi->dyno[2]= dl*n3[2]-shi->dy_u*n1[2]-shi->dy_v*n2[2];
930 if (mode & (MA_TANGENT_V|MA_NORMAP_TANG) || R.flag & R_NEED_TANGENT) {
931 float *tangent, *s1, *s2, *s3;
934 if(shi->vlr->flag & R_SMOOTH) {
940 /* qdn: flat faces have tangents too,
941 could pick either one, using average here */
947 shi->tang[0]= shi->tang[1]= shi->tang[2]= 0.0f;
948 shi->nmaptang[0]= shi->nmaptang[1]= shi->nmaptang[2]= 0.0f;
950 if(mode & MA_TANGENT_V) {
951 s1 = RE_vertren_get_tangent(obr, v1, 0);
952 s2 = RE_vertren_get_tangent(obr, v2, 0);
953 s3 = RE_vertren_get_tangent(obr, v3, 0);
956 shi->tang[0]= (tl*s3[0] - tu*s1[0] - tv*s2[0]);
957 shi->tang[1]= (tl*s3[1] - tu*s1[1] - tv*s2[1]);
958 shi->tang[2]= (tl*s3[2] - tu*s1[2] - tv*s2[2]);
960 if(obi->flag & R_TRANSFORMED)
961 mul_m3_v3(obi->nmat, shi->tang);
963 normalize_v3(shi->tang);
964 VECCOPY(shi->nmaptang, shi->tang);
968 if(mode & MA_NORMAP_TANG || R.flag & R_NEED_TANGENT) {
969 tangent= RE_vlakren_get_nmap_tangent(obr, shi->vlr, 0);
972 int j1= shi->i1, j2= shi->i2, j3= shi->i3;
973 float c0[3], c1[3], c2[3];
975 vlr_set_uv_indices(shi->vlr, &j1, &j2, &j3);
977 VECCOPY(c0, &tangent[j1*4]);
978 VECCOPY(c1, &tangent[j2*4]);
979 VECCOPY(c2, &tangent[j3*4]);
981 // keeping tangents normalized at vertex level
982 // corresponds better to how it's done in game engines
983 if(obi->flag & R_TRANSFORMED)
985 mul_mat3_m4_v3(obi->mat, c0); normalize_v3(c0);
986 mul_mat3_m4_v3(obi->mat, c1); normalize_v3(c1);
987 mul_mat3_m4_v3(obi->mat, c2); normalize_v3(c2);
990 // we don't normalize the interpolated TBN tangent
991 // corresponds better to how it's done in game engines
992 shi->nmaptang[0]= (tl*c2[0] - tu*c0[0] - tv*c1[0]);
993 shi->nmaptang[1]= (tl*c2[1] - tu*c0[1] - tv*c1[1]);
994 shi->nmaptang[2]= (tl*c2[2] - tu*c0[2] - tv*c1[2]);
996 // the sign is the same for all 3 vertices of any
997 // non degenerate triangle.
998 shi->nmaptang[3]= tangent[j1*4+3];
1003 if(mode & MA_STR_SURFDIFF) {
1004 float *surfnor= RE_vlakren_get_surfnor(obr, shi->vlr, 0);
1007 VECCOPY(shi->surfnor, surfnor)
1008 if(obi->flag & R_TRANSFORMED)
1009 mul_m3_v3(obi->nmat, shi->surfnor);
1012 VECCOPY(shi->surfnor, shi->vn)
1014 shi->surfdist= 0.0f;
1017 if(R.r.mode & R_SPEED) {
1018 float *s1, *s2, *s3;
1020 s1= RE_vertren_get_winspeed(obi, v1, 0);
1021 s2= RE_vertren_get_winspeed(obi, v2, 0);
1022 s3= RE_vertren_get_winspeed(obi, v3, 0);
1023 if(s1 && s2 && s3) {
1024 shi->winspeed[0]= (l*s3[0] - u*s1[0] - v*s2[0]);
1025 shi->winspeed[1]= (l*s3[1] - u*s1[1] - v*s2[1]);
1026 shi->winspeed[2]= (l*s3[2] - u*s1[2] - v*s2[2]);
1027 shi->winspeed[3]= (l*s3[3] - u*s1[3] - v*s2[3]);
1030 shi->winspeed[0]= shi->winspeed[1]= shi->winspeed[2]= shi->winspeed[3]= 0.0f;
1034 /* pass option forces UV calc */
1035 if(shi->passflag & SCE_PASS_UV)
1036 texco |= (NEED_UV|TEXCO_UV);
1038 /* texture coordinates. shi->dxuv shi->dyuv have been set */
1039 if(texco & NEED_UV) {
1041 if(texco & TEXCO_ORCO) {
1043 float *o1, *o2, *o3;
1049 shi->lo[0]= l*o3[0]-u*o1[0]-v*o2[0];
1050 shi->lo[1]= l*o3[1]-u*o1[1]-v*o2[1];
1051 shi->lo[2]= l*o3[2]-u*o1[2]-v*o2[2];
1054 dl= shi->dx_u+shi->dx_v;
1055 shi->dxlo[0]= dl*o3[0]-shi->dx_u*o1[0]-shi->dx_v*o2[0];
1056 shi->dxlo[1]= dl*o3[1]-shi->dx_u*o1[1]-shi->dx_v*o2[1];
1057 shi->dxlo[2]= dl*o3[2]-shi->dx_u*o1[2]-shi->dx_v*o2[2];
1058 dl= shi->dy_u+shi->dy_v;
1059 shi->dylo[0]= dl*o3[0]-shi->dy_u*o1[0]-shi->dy_v*o2[0];
1060 shi->dylo[1]= dl*o3[1]-shi->dy_u*o1[1]-shi->dy_v*o2[1];
1061 shi->dylo[2]= dl*o3[2]-shi->dy_u*o1[2]-shi->dy_v*o2[2];
1065 VECCOPY(shi->duplilo, obi->dupliorco);
1068 if(texco & TEXCO_GLOB) {
1069 VECCOPY(shi->gl, shi->co);
1070 mul_m4_v3(R.viewinv, shi->gl);
1072 VECCOPY(shi->dxgl, shi->dxco);
1073 mul_mat3_m4_v3(R.viewinv, shi->dxgl);
1074 VECCOPY(shi->dygl, shi->dyco);
1075 mul_mat3_m4_v3(R.viewinv, shi->dygl);
1079 if(texco & TEXCO_STRAND) {
1080 shi->strandco= (l*v3->accum - u*v1->accum - v*v2->accum);
1082 dl= shi->dx_u+shi->dx_v;
1083 shi->dxstrand= dl*v3->accum-shi->dx_u*v1->accum-shi->dx_v*v2->accum;
1084 dl= shi->dy_u+shi->dy_v;
1085 shi->dystrand= dl*v3->accum-shi->dy_u*v1->accum-shi->dy_v*v2->accum;
1089 if((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE))) {
1090 VlakRen *vlr= shi->vlr;
1094 int i, j1=shi->i1, j2=shi->i2, j3=shi->i3;
1096 /* uv and vcols are not copied on split, so set them according vlr divide flag */
1097 vlr_set_uv_indices(vlr, &j1, &j2, &j3);
1101 shi->actuv= obr->actmtface;
1102 shi->actcol= obr->actmcol;
1104 if(mode & (MA_VERTEXCOL|MA_VERTEXCOLP)) {
1105 for (i=0; (mcol=RE_vlakren_get_mcol(obr, vlr, i, &name, 0)); i++) {
1106 ShadeInputCol *scol= &shi->col[i];
1107 char *cp1, *cp2, *cp3;
1112 cp1= (char *)(mcol+j1);
1113 cp2= (char *)(mcol+j2);
1114 cp3= (char *)(mcol+j3);
1117 scol->col[3]= (l*((float)cp3[0]) - u*((float)cp1[0]) - v*((float)cp2[0]))/255.0f;
1119 /* try to prevent invalid color sampling of zero alpha points */
1120 if (!cp1[0]) cp1 = cp2; if (!cp1[0]) cp1 = cp3;
1121 if (!cp2[0]) cp2 = cp1; if (!cp2[0]) cp2 = cp3;
1122 if (!cp3[0]) cp3 = cp1; if (!cp3[0]) cp3 = cp2;
1124 /* sample color value */
1125 scol->col[0]= (l*((float)cp3[3]) - u*((float)cp1[3]) - v*((float)cp2[3]))/255.0f;
1126 scol->col[1]= (l*((float)cp3[2]) - u*((float)cp1[2]) - v*((float)cp2[2]))/255.0f;
1127 scol->col[2]= (l*((float)cp3[1]) - u*((float)cp1[1]) - v*((float)cp2[1]))/255.0f;
1131 shi->vcol[0]= shi->col[shi->actcol].col[0];
1132 shi->vcol[1]= shi->col[shi->actcol].col[1];
1133 shi->vcol[2]= shi->col[shi->actcol].col[2];
1134 shi->vcol[3]= shi->col[shi->actcol].col[3];
1144 for (i=0; (tface=RE_vlakren_get_tface(obr, vlr, i, &name, 0)); i++) {
1145 ShadeInputUV *suv= &shi->uv[i];
1146 float *uv1, *uv2, *uv3;
1155 suv->uv[0]= -1.0f + 2.0f*(l*uv3[0]-u*uv1[0]-v*uv2[0]);
1156 suv->uv[1]= -1.0f + 2.0f*(l*uv3[1]-u*uv1[1]-v*uv2[1]);
1157 suv->uv[2]= 0.0f; /* texture.c assumes there are 3 coords */
1162 dl= shi->dx_u+shi->dx_v;
1166 suv->dxuv[0]= 2.0f*(dl*uv3[0]-duv[0]*uv1[0]-duv[1]*uv2[0]);
1167 suv->dxuv[1]= 2.0f*(dl*uv3[1]-duv[0]*uv1[1]-duv[1]*uv2[1]);
1169 dl= shi->dy_u+shi->dy_v;
1173 suv->dyuv[0]= 2.0f*(dl*uv3[0]-duv[0]*uv1[0]-duv[1]*uv2[0]);
1174 suv->dyuv[1]= 2.0f*(dl*uv3[1]-duv[0]*uv1[1]-duv[1]*uv2[1]);
1177 if((mode & MA_FACETEXTURE) && i==obr->actmtface) {
1178 if((mode & (MA_VERTEXCOL|MA_VERTEXCOLP))==0) {
1184 if(tface && tface->tpage)
1185 render_realtime_texture(shi, tface->tpage);
1191 shi->dupliuv[0]= -1.0f + 2.0f*obi->dupliuv[0];
1192 shi->dupliuv[1]= -1.0f + 2.0f*obi->dupliuv[1];
1193 shi->dupliuv[2]= 0.0f;
1195 if(shi->totuv == 0) {
1196 ShadeInputUV *suv= &shi->uv[0];
1198 suv->uv[0]= 2.0f*(u+.5f);
1199 suv->uv[1]= 2.0f*(v+.5f);
1200 suv->uv[2]= 0.0f; /* texture.c assumes there are 3 coords */
1202 if(mode & MA_FACETEXTURE) {
1203 /* no tface? set at 1.0f */
1212 if(texco & TEXCO_NORM) {
1213 shi->orn[0]= -shi->vn[0];
1214 shi->orn[1]= -shi->vn[1];
1215 shi->orn[2]= -shi->vn[2];
1218 if(texco & TEXCO_STRESS) {
1219 float *s1, *s2, *s3;
1221 s1= RE_vertren_get_stress(obr, v1, 0);
1222 s2= RE_vertren_get_stress(obr, v2, 0);
1223 s3= RE_vertren_get_stress(obr, v3, 0);
1224 if(s1 && s2 && s3) {
1225 shi->stress= l*s3[0] - u*s1[0] - v*s2[0];
1226 if(shi->stress<1.0f) shi->stress-= 1.0f;
1227 else shi->stress= (shi->stress-1.0f)/shi->stress;
1229 else shi->stress= 0.0f;
1232 if(texco & TEXCO_TANGENT) {
1233 if((mode & MA_TANGENT_V)==0) {
1234 /* just prevent surprises */
1235 shi->tang[0]= shi->tang[1]= shi->tang[2]= 0.0f;
1236 shi->nmaptang[0]= shi->nmaptang[1]= shi->nmaptang[2]= 0.0f;
1241 /* this only avalailable for scanline renders */
1246 if(texco & TEXCO_WINDOW) {
1247 shi->winco[0]= -1.0f + 2.0f*x/(float)R.winx;
1248 shi->winco[1]= -1.0f + 2.0f*y/(float)R.winy;
1249 shi->winco[2]= 0.0f;
1251 shi->dxwin[0]= 2.0f/(float)R.winx;
1252 shi->dywin[1]= 2.0f/(float)R.winy;
1253 shi->dxwin[1]= shi->dxwin[2]= 0.0f;
1254 shi->dywin[0]= shi->dywin[2]= 0.0f;
1258 if(texco & TEXCO_STICKY) {
1259 float *s1, *s2, *s3;
1261 s1= RE_vertren_get_sticky(obr, v1, 0);
1262 s2= RE_vertren_get_sticky(obr, v2, 0);
1263 s3= RE_vertren_get_sticky(obr, v3, 0);
1265 if(s1 && s2 && s3) {
1266 float obwinmat[4][4], winmat[4][4], ho1[4], ho2[4], ho3[4];
1268 float hox, hoy, l, dl, u, v;
1269 float s00, s01, s10, s11, detsh;
1271 /* old globals, localized now */
1272 Zmulx= ((float)R.winx)/2.0f; Zmuly= ((float)R.winy)/2.0f;
1274 zbuf_make_winmat(&R, winmat);
1275 if(shi->obi->flag & R_TRANSFORMED)
1276 mul_m4_m4m4(obwinmat, obi->mat, winmat);
1278 copy_m4_m4(obwinmat, winmat);
1280 zbuf_render_project(obwinmat, v1->co, ho1);
1281 zbuf_render_project(obwinmat, v2->co, ho2);
1282 zbuf_render_project(obwinmat, v3->co, ho3);
1284 s00= ho3[0]/ho3[3] - ho1[0]/ho1[3];
1285 s01= ho3[1]/ho3[3] - ho1[1]/ho1[3];
1286 s10= ho3[0]/ho3[3] - ho2[0]/ho2[3];
1287 s11= ho3[1]/ho3[3] - ho2[1]/ho2[3];
1289 detsh= s00*s11-s10*s01;
1290 detsh= (detsh != 0.0f)? 1.0f/detsh: 0.0f;
1291 s00*= detsh; s01*=detsh;
1292 s10*=detsh; s11*=detsh;
1294 /* recalc u and v again */
1297 u= (hox - ho3[0]/ho3[3])*s11 - (hoy - ho3[1]/ho3[3])*s10;
1298 v= (hoy - ho3[1]/ho3[3])*s00 - (hox - ho3[0]/ho3[3])*s01;
1301 shi->sticky[0]= l*s3[0]-u*s1[0]-v*s2[0];
1302 shi->sticky[1]= l*s3[1]-u*s1[1]-v*s2[1];
1303 shi->sticky[2]= 0.0f;
1306 float dxuv[2], dyuv[2];
1308 dxuv[1]= - s01/Zmulx;
1309 dyuv[0]= - s10/Zmuly;
1312 dl= dxuv[0] + dxuv[1];
1313 shi->dxsticky[0]= dl*s3[0] - dxuv[0]*s1[0] - dxuv[1]*s2[0];
1314 shi->dxsticky[1]= dl*s3[1] - dxuv[0]*s1[1] - dxuv[1]*s2[1];
1315 dl= dyuv[0] + dyuv[1];
1316 shi->dysticky[0]= dl*s3[0] - dyuv[0]*s1[0] - dyuv[1]*s2[0];
1317 shi->dysticky[1]= dl*s3[1] - dyuv[0]*s1[1] - dyuv[1]*s2[1];
1322 Note! For raytracing winco is not set, important because thus means all shader input's need to have their variables set to zero else in-initialized values are used
1324 if (shi->do_manage) {
1325 if(mode & (MA_VERTEXCOL|MA_VERTEXCOLP|MA_FACETEXTURE)) {
1326 srgb_to_linearrgb_v3_v3(shi->vcol, shi->vcol);
1332 /* ****************** ShadeSample ************************************** */
1334 /* initialize per part, not per pixel! */
1335 void shade_input_initialize(ShadeInput *shi, RenderPart *pa, RenderLayer *rl, int sample)
1338 memset(shi, 0, sizeof(ShadeInput));
1340 shi->sample= sample;
1341 shi->thread= pa->thread;
1342 shi->do_preview= (R.r.scemode & R_MATNODE_PREVIEW) != 0;
1343 shi->do_manage= (R.r.color_mgt_flag & R_COLOR_MANAGEMENT);
1345 shi->layflag= rl->layflag;
1346 shi->passflag= rl->passflag;
1347 shi->combinedflag= ~rl->pass_xor;
1348 shi->mat_override= rl->mat_override;
1349 shi->light_override= rl->light_override;
1351 /* note shi.depth==0 means first hit, not raytracing */
1355 /* initialize per part, not per pixel! */
1356 void shade_sample_initialize(ShadeSample *ssamp, RenderPart *pa, RenderLayer *rl)
1360 tot= R.osa==0?1:R.osa;
1362 for(a=0; a<tot; a++) {
1363 shade_input_initialize(&ssamp->shi[a], pa, rl, a);
1364 memset(&ssamp->shr[a], 0, sizeof(ShadeResult));
1367 get_sample_layers(pa, rl, ssamp->rlpp);
1370 /* Do AO or (future) GI */
1371 void shade_samples_do_AO(ShadeSample *ssamp)
1376 if(!(R.r.mode & R_SHADOW))
1378 if(!(R.r.mode & R_RAYTRACE) && !(R.wrld.ao_gather_method == WO_AOGATHER_APPROX))
1381 if(R.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) {
1382 shi= &ssamp->shi[0];
1384 if(((shi->passflag & SCE_PASS_COMBINED) && (shi->combinedflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT)))
1385 || (shi->passflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT)))
1386 for(sample=0, shi= ssamp->shi; sample<ssamp->tot; shi++, sample++)
1387 if(!(shi->mode & MA_SHLESS))
1388 ambient_occlusion(shi); /* stores in shi->ao[] */
1393 void shade_samples_fill_with_ps(ShadeSample *ssamp, PixStr *ps, int x, int y)
1400 for(shi= ssamp->shi; ps; ps= ps->next) {
1401 shade_input_set_triangle(shi, ps->obi, ps->facenr, 1);
1403 if(shi->vlr) { /* NULL happens for env material or for 'all z' */
1404 unsigned short curmask= ps->mask;
1406 /* full osa is only set for OSA renders */
1407 if(shi->vlr->flag & R_FULL_OSA) {
1408 short shi_cp= 0, samp;
1410 for(samp=0; samp<R.osa; samp++) {
1411 if(curmask & (1<<samp)) {
1412 /* zbuffer has this inverse corrected, ensures xs,ys are inside pixel */
1413 xs= (float)x + R.jit[samp][0] + 0.5f;
1414 ys= (float)y + R.jit[samp][1] + 0.5f;
1417 shade_input_copy_triangle(shi, shi-1);
1419 shi->mask= (1<<samp);
1420 // shi->rl= ssamp->rlpp[samp];
1421 shi->samplenr= R.shadowsamplenr[shi->thread]++; /* this counter is not being reset per pixel */
1422 shade_input_set_viewco(shi, x, y, xs, ys, (float)ps->z);
1423 shade_input_set_uv(shi);
1425 shade_input_set_normals(shi);
1426 else /* XXX shi->flippednor messes up otherwise */
1427 shade_input_set_vertex_normals(shi);
1436 short b= R.samples->centmask[curmask];
1437 xs= (float)x + R.samples->centLut[b & 15] + 0.5f;
1438 ys= (float)y + R.samples->centLut[b>>4] + 0.5f;
1441 xs= (float)x + 0.5f;
1442 ys= (float)y + 0.5f;
1446 shi->samplenr= R.shadowsamplenr[shi->thread]++;
1447 shade_input_set_viewco(shi, x, y, xs, ys, (float)ps->z);
1448 shade_input_set_uv(shi);
1449 shade_input_set_normals(shi);
1453 /* total sample amount, shi->sample is static set in initialize */
1455 ssamp->tot= (shi-1)->sample + 1;
1460 /* shades samples, returns true if anything happened */
1461 int shade_samples(ShadeSample *ssamp, PixStr *ps, int x, int y)
1463 shade_samples_fill_with_ps(ssamp, ps, x, y);
1466 ShadeInput *shi= ssamp->shi;
1467 ShadeResult *shr= ssamp->shr;
1470 /* if shadow or AO? */
1471 shade_samples_do_AO(ssamp);
1473 /* if shade (all shadepinputs have same passflag) */
1474 if(ssamp->shi[0].passflag & ~(SCE_PASS_Z|SCE_PASS_INDEXOB|SCE_PASS_INDEXMA)) {
1476 for(samp=0; samp<ssamp->tot; samp++, shi++, shr++) {
1477 shade_input_set_shade_texco(shi);
1478 shade_input_do_shade(shi, shr);
1481 else if(shi->passflag & SCE_PASS_Z) {
1482 for(samp=0; samp<ssamp->tot; samp++, shi++, shr++)
1483 shr->z= -shi->co[2];