Merge branch 'master' into blender2.8
[blender.git] / source / blender / render / intern / source / render_result.c
index a79d0c3..c259a60 100644 (file)
@@ -266,9 +266,7 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf
        RenderResult *rr;
        RenderLayer *rl;
        RenderView *rv;
-       SceneRenderLayer *srl;
        int rectx, recty;
-       int nr;
 
        rectx = BLI_rcti_size_x(partrct);
        recty = BLI_rcti_size_y(partrct);
@@ -296,33 +294,21 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf
        render_result_views_new(rr, &re->r);
 
        /* check renderdata for amount of layers */
-       for (nr = 0, srl = re->r.layers.first; srl; srl = srl->next, nr++) {
-
-               if (layername && layername[0])
-                       if (!STREQ(srl->name, layername))
-                               continue;
-
-               if (re->r.scemode & R_SINGLE_LAYER) {
-                       if (nr != re->r.actlay)
-                               continue;
-               }
-               else {
-                       if (srl->layflag & SCE_LAY_DISABLE)
+       FOREACH_VIEW_LAYER_TO_RENDER_BEGIN(re, view_layer)
+       {
+               if (layername && layername[0]) {
+                       if (!STREQ(view_layer->name, layername)) {
                                continue;
+                       }
                }
 
                rl = MEM_callocN(sizeof(RenderLayer), "new render layer");
                BLI_addtail(&rr->layers, rl);
 
-               BLI_strncpy(rl->name, srl->name, sizeof(rl->name));
-               rl->lay = srl->lay;
-               rl->lay_zmask = srl->lay_zmask;
-               rl->lay_exclude = srl->lay_exclude;
-               rl->layflag = srl->layflag;
-               rl->passflag = srl->passflag; /* for debugging: srl->passflag | SCE_PASS_RAYHITS; */
-               rl->pass_xor = srl->pass_xor;
-               rl->light_override = srl->light_override;
-               rl->mat_override = srl->mat_override;
+               BLI_strncpy(rl->name, view_layer->name, sizeof(rl->name));
+               rl->layflag = view_layer->layflag;
+               rl->passflag = view_layer->passflag; /* for debugging: view_layer->passflag | SCE_PASS_RAYHITS; */
+               rl->pass_xor = view_layer->pass_xor;
                rl->rectx = rectx;
                rl->recty = recty;
 
@@ -357,70 +343,72 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf
                        /* a renderlayer should always have a Combined pass*/
                        render_layer_add_pass(rr, rl, 4, "Combined", view, "RGBA");
 
-                       if (srl->passflag  & SCE_PASS_Z)
+                       if (view_layer->passflag  & SCE_PASS_Z)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 1, RE_PASSNAME_Z, view, "Z");
-                       if (srl->passflag  & SCE_PASS_VECTOR)
+                       if (view_layer->passflag  & SCE_PASS_VECTOR)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 4, RE_PASSNAME_VECTOR, view, "XYZW");
-                       if (srl->passflag  & SCE_PASS_NORMAL)
+                       if (view_layer->passflag  & SCE_PASS_NORMAL)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_NORMAL, view, "XYZ");
-                       if (srl->passflag  & SCE_PASS_UV)
+                       if (view_layer->passflag  & SCE_PASS_UV)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_UV, view, "UVA");
-                       if (srl->passflag  & SCE_PASS_RGBA)
+                       if (view_layer->passflag  & SCE_PASS_RGBA)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 4, RE_PASSNAME_RGBA, view, "RGBA");
-                       if (srl->passflag  & SCE_PASS_EMIT)
+                       if (view_layer->passflag  & SCE_PASS_EMIT)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_EMIT, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_DIFFUSE)
+                       if (view_layer->passflag  & SCE_PASS_DIFFUSE)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_DIFFUSE, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_SPEC)
+                       if (view_layer->passflag  & SCE_PASS_SPEC)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_SPEC, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_AO)
+                       if (view_layer->passflag  & SCE_PASS_AO)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_AO, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_ENVIRONMENT)
+                       if (view_layer->passflag  & SCE_PASS_ENVIRONMENT)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_ENVIRONMENT, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_INDIRECT)
+                       if (view_layer->passflag  & SCE_PASS_INDIRECT)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_INDIRECT, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_SHADOW)
+                       if (view_layer->passflag  & SCE_PASS_SHADOW)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_SHADOW, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_REFLECT)
+                       if (view_layer->passflag  & SCE_PASS_REFLECT)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_REFLECT, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_REFRACT)
+                       if (view_layer->passflag  & SCE_PASS_REFRACT)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_REFRACT, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_INDEXOB)
+                       if (view_layer->passflag  & SCE_PASS_INDEXOB)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 1, RE_PASSNAME_INDEXOB, view, "X");
-                       if (srl->passflag  & SCE_PASS_INDEXMA)
+                       if (view_layer->passflag  & SCE_PASS_INDEXMA)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 1, RE_PASSNAME_INDEXMA, view, "X");
-                       if (srl->passflag  & SCE_PASS_MIST)
+                       if (view_layer->passflag  & SCE_PASS_MIST)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 1, RE_PASSNAME_MIST, view, "Z");
                        if (rl->passflag & SCE_PASS_RAYHITS)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 4, RE_PASSNAME_RAYHITS, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_DIFFUSE_DIRECT)
+                       if (view_layer->passflag  & SCE_PASS_DIFFUSE_DIRECT)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_DIFFUSE_DIRECT, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_DIFFUSE_INDIRECT)
+                       if (view_layer->passflag  & SCE_PASS_DIFFUSE_INDIRECT)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_DIFFUSE_INDIRECT, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_DIFFUSE_COLOR)
+                       if (view_layer->passflag  & SCE_PASS_DIFFUSE_COLOR)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_DIFFUSE_COLOR, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_GLOSSY_DIRECT)
+                       if (view_layer->passflag  & SCE_PASS_GLOSSY_DIRECT)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_GLOSSY_DIRECT, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_GLOSSY_INDIRECT)
+                       if (view_layer->passflag  & SCE_PASS_GLOSSY_INDIRECT)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_GLOSSY_INDIRECT, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_GLOSSY_COLOR)
+                       if (view_layer->passflag  & SCE_PASS_GLOSSY_COLOR)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_GLOSSY_COLOR, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_TRANSM_DIRECT)
+                       if (view_layer->passflag  & SCE_PASS_TRANSM_DIRECT)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_TRANSM_DIRECT, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_TRANSM_INDIRECT)
+                       if (view_layer->passflag  & SCE_PASS_TRANSM_INDIRECT)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_TRANSM_INDIRECT, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_TRANSM_COLOR)
+                       if (view_layer->passflag  & SCE_PASS_TRANSM_COLOR)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_TRANSM_COLOR, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_SUBSURFACE_DIRECT)
+                       if (view_layer->passflag  & SCE_PASS_SUBSURFACE_DIRECT)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_SUBSURFACE_DIRECT, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_SUBSURFACE_INDIRECT)
+                       if (view_layer->passflag  & SCE_PASS_SUBSURFACE_INDIRECT)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_SUBSURFACE_INDIRECT, view, "RGB");
-                       if (srl->passflag  & SCE_PASS_SUBSURFACE_COLOR)
+                       if (view_layer->passflag  & SCE_PASS_SUBSURFACE_COLOR)
                                RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_SUBSURFACE_COLOR, view, "RGB");
 #undef RENDER_LAYER_ADD_PASS_SAFE
                }
        }
-       /* sss, previewrender and envmap don't do layers, so we make a default one */
+       FOREACH_VIEW_LAYER_TO_RENDER_END;
+
+       /* previewrender doesn't do layers, so we make a default one */
        if (BLI_listbase_is_empty(&rr->layers) && !(layername && layername[0])) {
                rl = MEM_callocN(sizeof(RenderLayer), "new render layer");
                BLI_addtail(&rr->layers, rl);
@@ -449,11 +437,10 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf
                }
 
                /* note, this has to be in sync with scene.c */
-               rl->lay = (1 << 20) - 1;
                rl->layflag = 0x7FFF;    /* solid ztra halo strand */
                rl->passflag = SCE_PASS_COMBINED;
 
-               re->r.actlay = 0;
+               re->active_view_layer = 0;
        }
 
        /* border render; calculate offset for use in compositor. compo is centralized coords */
@@ -518,23 +505,6 @@ void render_result_add_pass(RenderResult *rr, const char *name, int channels, co
        }
 }
 
-/* allocate osa new results for samples */
-RenderResult *render_result_new_full_sample(Render *re, ListBase *lb, rcti *partrct, int crop, int savebuffers, const char *viewname)
-{
-       int a;
-
-       if (re->osa == 0)
-               return render_result_new(re, partrct, crop, savebuffers, RR_ALL_LAYERS, viewname);
-
-       for (a = 0; a < re->osa; a++) {
-               RenderResult *rr = render_result_new(re, partrct, crop, savebuffers, RR_ALL_LAYERS, viewname);
-               BLI_addtail(lb, rr);
-               rr->sample_nr = a;
-       }
-
-       return lb->first;
-}
-
 static int passtype_from_name(const char *name)
 {
        const char delim[] = {'.', '\0'};
@@ -994,7 +964,7 @@ void render_result_single_layer_begin(Render *re)
 /* if scemode is R_SINGLE_LAYER, at end of rendering, merge the both render results */
 void render_result_single_layer_end(Render *re)
 {
-       SceneRenderLayer *srl;
+       ViewLayer *view_layer;
        RenderLayer *rlpush;
        RenderLayer *rl;
        int nr;
@@ -1015,12 +985,12 @@ void render_result_single_layer_end(Render *re)
                BLI_remlink(&re->result->layers, rl);
 
                /* reconstruct render result layers */
-               for (nr = 0, srl = re->r.layers.first; srl; srl = srl->next, nr++) {
-                       if (nr == re->r.actlay) {
+               for (nr = 0, view_layer = re->view_layers.first; view_layer; view_layer = view_layer->next, nr++) {
+                       if (nr == re->active_view_layer) {
                                BLI_addtail(&re->result->layers, rl);
                        }
                        else {
-                               rlpush = RE_GetRenderLayer(re->pushedresult, srl->name);
+                               rlpush = RE_GetRenderLayer(re->pushedresult, view_layer->name);
                                if (rlpush) {
                                        BLI_remlink(&re->pushedresult->layers, rlpush);
                                        BLI_addtail(&re->result->layers, rlpush);
@@ -1103,8 +1073,8 @@ void render_result_save_empty_result_tiles(Render *re)
                for (rl = rr->layers.first; rl; rl = rl->next) {
                        for (pa = re->parts.first; pa; pa = pa->next) {
                                if (pa->status != PART_STATUS_MERGED) {
-                                       int party = pa->disprect.ymin - re->disprect.ymin + pa->crop;
-                                       int partx = pa->disprect.xmin - re->disprect.xmin + pa->crop;
+                                       int party = pa->disprect.ymin - re->disprect.ymin;
+                                       int partx = pa->disprect.xmin - re->disprect.xmin;
                                        IMB_exrtile_write_channels(rl->exrhandle, partx, party, 0, re->viewname, true);
                                }
                        }