Multi-View and Stereo 3D
[blender-staging.git] / source / blender / render / intern / source / rendercore.c
index 5b054005bacfee6badffbb0b88a61a171df9af83..99611a9c5a8f1f14290fa1da7a298a4cd9677c2c 100644 (file)
@@ -181,8 +181,10 @@ static void halo_pixelstruct(HaloRen *har, RenderLayer **rlpp, int totsample, in
 
                                if (fullsample) {
                                        for (sample=0; sample<totsample; sample++)
-                                               if (ps->mask & (1 << sample))
-                                                       addalphaAddfacFloat(rlpp[sample]->rectf + od*4, col, har->add);
+                                               if (ps->mask & (1 << sample)) {
+                                                       float *pass = RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_COMBINED, R.viewname);
+                                                       addalphaAddfacFloat(pass + od*4, col, har->add);
+                                               }
                                }
                                else {
                                        fac= ((float)amountm)/(float)R.osa;
@@ -214,8 +216,10 @@ static void halo_pixelstruct(HaloRen *har, RenderLayer **rlpp, int totsample, in
 
        if (fullsample) {
                for (sample=0; sample<totsample; sample++)
-                       if (!(mask & (1 << sample)))
-                               addalphaAddfacFloat(rlpp[sample]->rectf + od*4, col, har->add);
+                       if (!(mask & (1 << sample))) {
+                               float *pass = RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_COMBINED, R.viewname);
+                               addalphaAddfacFloat(pass + od*4, col, har->add);
+                       }
        }
        else {
                col[0]= accol[0];
@@ -223,8 +227,10 @@ static void halo_pixelstruct(HaloRen *har, RenderLayer **rlpp, int totsample, in
                col[2]= accol[2];
                col[3]= accol[3];
                
-               for (sample=0; sample<totsample; sample++)
-                       addalphaAddfacFloat(rlpp[sample]->rectf + od*4, col, har->add);
+               for (sample=0; sample<totsample; sample++) {
+                       float *pass = RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_COMBINED, R.viewname);
+                       addalphaAddfacFloat(pass + od*4, col, har->add);
+               }
        }
 }
 
@@ -305,8 +311,10 @@ static void halo_tile(RenderPart *pa, RenderLayer *rl)
                                                                zz= calchalo_z(har, *rz);
                                                                if ((zz> har->zs) || (har->mat && (har->mat->mode & MA_HALO_SOFT))) {
                                                                        if (shadeHaloFloat(har, col, zz, dist, xn, yn, har->flarec)) {
-                                                                               for (sample=0; sample<totsample; sample++)
-                                                                                       addalphaAddfacFloat(rlpp[sample]->rectf + od*4, col, har->add);
+                                                                               for (sample=0; sample<totsample; sample++) {
+                                                                                       float * rect= RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_COMBINED, R.viewname);
+                                                                                       addalphaAddfacFloat(rect + od*4, col, har->add);
+                                                                               }
                                                                        }
                                                                }
                                                        }
@@ -359,7 +367,8 @@ static void lamphalo_tile(RenderPart *pa, RenderLayer *rl)
                                        if (fullsample) {
                                                for (sample=0; sample<totsample; sample++) {
                                                        if (ps->mask & (1 << sample)) {
-                                                               pass= rlpp[sample]->rectf + od*4;
+                                                               pass = RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_COMBINED, R.viewname);
+                                                               pass += od * 4;
                                                                pass[0]+= col[0];
                                                                pass[1]+= col[1];
                                                                pass[2]+= col[2];
@@ -370,7 +379,8 @@ static void lamphalo_tile(RenderPart *pa, RenderLayer *rl)
                                        }
                                        else {
                                                fac= ((float)count)/(float)R.osa;
-                                               pass= rl->rectf + od*4;
+                                               pass = RE_RenderLayerGetPass(rl, SCE_PASS_COMBINED, R.viewname);
+                                               pass += od * 4;
                                                pass[0]+= fac*col[0];
                                                pass[1]+= fac*col[1];
                                                pass[2]+= fac*col[2];
@@ -390,7 +400,9 @@ static void lamphalo_tile(RenderPart *pa, RenderLayer *rl)
                                        if (fullsample) {
                                                for (sample=0; sample<totsample; sample++) {
                                                        if (!(mask & (1 << sample))) {
-                                                               pass= rlpp[sample]->rectf + od*4;
+
+                                                               pass = RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_COMBINED, R.viewname);
+                                                               pass += od * 4;
                                                                pass[0]+= col[0];
                                                                pass[1]+= col[1];
                                                                pass[2]+= col[2];
@@ -401,7 +413,8 @@ static void lamphalo_tile(RenderPart *pa, RenderLayer *rl)
                                        }
                                        else {
                                                fac= ((float)R.osa-totsamp)/(float)R.osa;
-                                               pass= rl->rectf + od*4;
+                                               pass = RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_COMBINED, R.viewname);
+                                               pass += od * 4;
                                                pass[0]+= fac*col[0];
                                                pass[1]+= fac*col[1];
                                                pass[2]+= fac*col[2];
@@ -420,7 +433,8 @@ static void lamphalo_tile(RenderPart *pa, RenderLayer *rl)
                                renderspothalo(&shi, col, 1.0f);
 
                                for (sample=0; sample<totsample; sample++) {
-                                       pass= rlpp[sample]->rectf + od*4;
+                                       pass = RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_COMBINED, R.viewname);
+                                       pass += od * 4;
                                        pass[0]+= col[0];
                                        pass[1]+= col[1];
                                        pass[2]+= col[2];
@@ -444,14 +458,14 @@ static void add_filt_passes(RenderLayer *rl, int curmask, int rectx, int offset,
 {
        RenderPass *rpass;
 
-       /* combined rgb */
-       add_filt_fmask(curmask, shr->combined, rl->rectf + 4*offset, rectx);
-       
        for (rpass= rl->passes.first; rpass; rpass= rpass->next) {
                float *fp, *col= NULL;
                int pixsize= 3;
                
                switch (rpass->passtype) {
+                       case SCE_PASS_COMBINED:
+                               add_filt_fmask(curmask, shr->combined, rpass->rect + 4*offset, rectx);
+                               break;
                        case SCE_PASS_Z:
                                fp= rpass->rect + offset;
                                *fp= shr->z;
@@ -555,15 +569,16 @@ static void add_passes(RenderLayer *rl, int offset, ShadeInput *shi, ShadeResult
 {
        RenderPass *rpass;
        float *fp;
-       
-       fp= rl->rectf + 4*offset;
-       copy_v4_v4(fp, shr->combined);
-       
+
        for (rpass= rl->passes.first; rpass; rpass= rpass->next) {
                float *col= NULL, uvcol[3];
                int a, pixsize= 3;
                
                switch (rpass->passtype) {
+                       case SCE_PASS_COMBINED:
+                               /* copy combined to use for preview */
+                               copy_v4_v4(rpass->rect + 4*offset, shr->combined);
+                               break;
                        case SCE_PASS_Z:
                                fp= rpass->rect + offset;
                                *fp= shr->z;
@@ -681,7 +696,8 @@ static void sky_tile(RenderPart *pa, RenderLayer *rl)
                        bool done = false;
                        
                        for (sample= 0; sample<totsample; sample++) {
-                               float *pass= rlpp[sample]->rectf + od;
+                               float *pass = RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_COMBINED, R.viewname);
+                               pass += od;
                                
                                if (pass[3]<1.0f) {
                                        
@@ -742,8 +758,8 @@ static void atm_tile(RenderPart *pa, RenderLayer *rl)
                        int sample;
                        
                        for (sample=0; sample<totsample; sample++) {
-                               const float *zrect= RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_Z) + od;
-                               float *rgbrect = rlpp[sample]->rectf + 4*od;
+                               const float *zrect = RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_Z, R.viewname) + od;
+                               float *rgbrect = RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_COMBINED, R.viewname) + 4*od;
                                float rgb[3] = {0};
                                bool done = false;
                                
@@ -978,8 +994,8 @@ static void clamp_alpha_rgb_range(RenderPart *pa, RenderLayer *rl)
                return;
        
        for (sample= 0; sample<totsample; sample++) {
-               float *rectf= rlpp[sample]->rectf;
-               
+               float *rectf = RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_COMBINED, R.viewname);
+
                for (y= pa->rectx*pa->recty; y>0; y--, rectf+=4) {
                        rectf[0] = MAX2(rectf[0], 0.0f);
                        rectf[1] = MAX2(rectf[1], 0.0f);
@@ -1060,7 +1076,7 @@ static void reset_sky_speed(RenderPart *pa, RenderLayer *rl)
        totsample= get_sample_layers(pa, rl, rlpp);
 
        for (sample= 0; sample<totsample; sample++) {
-               fp= RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_VECTOR);
+               fp= RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_VECTOR, R.viewname);
                if (fp==NULL) break;
 
                for (a= 4*pa->rectx*pa->recty - 1; a>=0; a--)
@@ -1171,6 +1187,8 @@ void zbufshadeDA_tile(RenderPart *pa)
        pa->rectp= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectp");
        pa->rectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz");
        for (rl= rr->layers.first; rl; rl= rl->next) {
+               float *rect = RE_RenderLayerGetPass(rl, SCE_PASS_COMBINED, R.viewname);
+
                if ((rl->layflag & SCE_LAY_ZMASK) && (rl->layflag & SCE_LAY_NEG_ZMASK))
                        pa->rectmask= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectmask");
        
@@ -1211,7 +1229,7 @@ void zbufshadeDA_tile(RenderPart *pa)
                if (R.flag & R_ZTRA || R.totstrand) {
                        if (rl->layflag & (SCE_LAY_ZTRA|SCE_LAY_STRAND)) {
                                if (pa->fullresult.first) {
-                                       zbuffer_transp_shade(pa, rl, rl->rectf, &psmlist);
+                                       zbuffer_transp_shade(pa, rl, rect, &psmlist);
                                }
                                else {
                                        unsigned short *ztramask, *solidmask= NULL; /* 16 bits, MAX_OSA */
@@ -1220,9 +1238,9 @@ void zbufshadeDA_tile(RenderPart *pa)
                                        rl->acolrect= MEM_callocN(4*sizeof(float)*pa->rectx*pa->recty, "alpha layer");
                                        
                                        /* swap for live updates, and it is used in zbuf.c!!! */
-                                       SWAP(float *, rl->acolrect, rl->rectf);
-                                       ztramask= zbuffer_transp_shade(pa, rl, rl->rectf, &psmlist);
-                                       SWAP(float *, rl->acolrect, rl->rectf);
+                                       SWAP(float *, rl->acolrect, rect);
+                                       ztramask = zbuffer_transp_shade(pa, rl, rect, &psmlist);
+                                       SWAP(float *, rl->acolrect, rect);
                                        
                                        /* zbuffer transp only returns ztramask if there's solid rendered */
                                        if (ztramask)
@@ -1231,7 +1249,8 @@ void zbufshadeDA_tile(RenderPart *pa)
                                        if (ztramask && solidmask) {
                                                unsigned short *sps= solidmask, *spz= ztramask;
                                                unsigned short fullmask= (1<<R.osa)-1;
-                                               float *fcol= rl->rectf; float *acol= rl->acolrect;
+                                               float *fcol= rect;
+                                               float *acol= rl->acolrect;
                                                int x;
                                                
                                                for (x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4, sps++, spz++) {
@@ -1242,7 +1261,8 @@ void zbufshadeDA_tile(RenderPart *pa)
                                                }
                                        }
                                        else {
-                                               float *fcol= rl->rectf; float *acol= rl->acolrect;
+                                               float *fcol= rect;
+                                               float *acol= rl->acolrect;
                                                int x;
                                                for (x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4) {
                                                        addAlphaOverFloat(fcol, acol);
@@ -1265,7 +1285,7 @@ void zbufshadeDA_tile(RenderPart *pa)
                /* extra layers */
                if (rl->layflag & SCE_LAY_EDGE) 
                        if (R.r.mode & R_EDGE) 
-                               edge_enhance_add(pa, rl->rectf, edgerect);
+                               edge_enhance_add(pa, rect, edgerect);
                
                if (rl->passflag & SCE_PASS_VECTOR)
                        reset_sky_speed(pa, rl);
@@ -1319,6 +1339,7 @@ void zbufshade_tile(RenderPart *pa)
        pa->rectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz");
 
        for (rl= rr->layers.first; rl; rl= rl->next) {
+               float *rect= RE_RenderLayerGetPass(rl, SCE_PASS_COMBINED, R.viewname);
                if ((rl->layflag & SCE_LAY_ZMASK) && (rl->layflag & SCE_LAY_NEG_ZMASK))
                        pa->rectmask= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectmask");
 
@@ -1342,7 +1363,7 @@ void zbufshade_tile(RenderPart *pa)
                        rr->renlay= rl;
                        
                        if (rl->layflag & SCE_LAY_SOLID) {
-                               const float *fcol= rl->rectf;
+                               const float *fcol = rect;
                                const int *ro= pa->recto, *rp= pa->rectp, *rz= pa->rectz;
                                int x, y, offs=0, seed;
                                
@@ -1405,11 +1426,11 @@ void zbufshade_tile(RenderPart *pa)
                                rl->acolrect= MEM_callocN(4*sizeof(float)*pa->rectx*pa->recty, "alpha layer");
                                
                                /* swap for live updates */
-                               SWAP(float *, rl->acolrect, rl->rectf);
-                               zbuffer_transp_shade(pa, rl, rl->rectf, NULL);
-                               SWAP(float *, rl->acolrect, rl->rectf);
+                               SWAP(float *, rl->acolrect, rect);
+                               zbuffer_transp_shade(pa, rl, rect, NULL);
+                               SWAP(float *, rl->acolrect, rect);
                                
-                               fcol= rl->rectf; acol= rl->acolrect;
+                               fcol= rect; acol= rl->acolrect;
                                for (x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4) {
                                        addAlphaOverFloat(fcol, acol);
                                }
@@ -1427,7 +1448,7 @@ void zbufshade_tile(RenderPart *pa)
                if (!R.test_break(R.tbh)) {
                        if (rl->layflag & SCE_LAY_EDGE) 
                                if (R.r.mode & R_EDGE)
-                                       edge_enhance_add(pa, rl->rectf, edgerect);
+                                       edge_enhance_add(pa, rect, edgerect);
                }
                
                if (rl->passflag & SCE_PASS_VECTOR)
@@ -1654,7 +1675,7 @@ void zbufshade_sss_tile(RenderPart *pa)
                return;
        }
        
-       fcol= rl->rectf;
+       fcol= RE_RenderLayerGetPass(rl, SCE_PASS_COMBINED, R.viewname);
 
        co= MEM_mallocN(sizeof(float)*3*handle.totps, "SSSCo");
        color= MEM_mallocN(sizeof(float)*3*handle.totps, "SSSColor");
@@ -1938,6 +1959,7 @@ void add_halo_flare(Render *re)
        RenderLayer *rl;
        HaloRen *har;
        int a, mode;
+       float *rect;
        
        /* for now, we get the first renderlayer in list with halos set */
        for (rl= rr->layers.first; rl; rl= rl->next) {
@@ -1945,8 +1967,11 @@ void add_halo_flare(Render *re)
                
                if ((rl->layflag & SCE_LAY_HALO) == 0)
                        continue;
-               if (rl->rectf==NULL)
-                       continue;
+
+               rect = RE_RenderLayerGetPass(rl, SCE_PASS_COMBINED, re->viewname);
+
+               if (rl==NULL || rect)
+                       return;
                
                mode= R.r.mode;
                R.r.mode &= ~R_PANORAMA;
@@ -1958,7 +1983,7 @@ void add_halo_flare(Render *re)
                        
                        if (har->flarec && (har->lay & rl->lay)) {
                                do_draw = true;
-                               renderflare(rr, rl->rectf, har);
+                               renderflare(rr, rect, har);
                        }
                }