Fix border rendering for eevee + stop passing render result around
authorDalai Felinto <dfelinto@gmail.com>
Fri, 23 Feb 2018 16:26:28 +0000 (13:26 -0300)
committerDalai Felinto <dfelinto@gmail.com>
Fri, 23 Feb 2018 16:26:30 +0000 (13:26 -0300)
Technically the original issue is that xof/yof in render result is calculated
for drawing border render. So a simpler patch could be:

```
- rr->xof = re->disprect.xmin;
+ rr->xof = re->disprect.xmin + BLI_rcti_cent_x(&re->disprect) - (re->winx / 2);
```

However everywhere in the code we are getting border directly from re->disprect
which we may as well do here too.

Besides I'm taking this as a chance to get rid of RenderResult in the internal
loop of eevee, to help prepare the code to the upcoming rendering pipeline
changes.

source/blender/draw/engines/eevee/eevee_engine.c
source/blender/draw/engines/eevee/eevee_private.h
source/blender/draw/engines/eevee/eevee_render.c
source/blender/draw/intern/DRW_render.h
source/blender/draw/intern/draw_manager.c

index 4a7258d65253491b287877de36f7e8ebd35d47b8..c1c298417e8ce2282666268b7127b61495f06bae 100644 (file)
@@ -377,7 +377,7 @@ static void eevee_id_update(void *vedata, ID *id)
        }
 }
 
-static void eevee_render_to_image(void *vedata, RenderEngine *engine, struct RenderResult *render_result, struct RenderLayer *render_layer)
+static void eevee_render_to_image(void *vedata, RenderEngine *engine, struct RenderLayer *render_layer, const rcti *rect)
 {
        const DRWContextState *draw_ctx = DRW_context_state_get();
        EEVEE_render_init(vedata, engine, draw_ctx->depsgraph);
@@ -385,7 +385,7 @@ static void eevee_render_to_image(void *vedata, RenderEngine *engine, struct Ren
        DRW_render_object_iter(vedata, engine, draw_ctx->depsgraph, EEVEE_render_cache);
 
        /* Actually do the rendering. */
-       EEVEE_render_draw(vedata, engine, render_result, render_layer);
+       EEVEE_render_draw(vedata, engine, render_layer, rect);
 }
 
 static void eevee_engine_free(void)
index 85d6dd8b4485ff5bfec2393e972d2034a0c6f44f..8039fa6e946f05acfe22b5f7039443e80fb29e3a 100644 (file)
@@ -888,7 +888,7 @@ void EEVEE_effects_free(void);
 /* eevee_render.c */
 void EEVEE_render_init(EEVEE_Data *vedata, struct RenderEngine *engine, struct Depsgraph *depsgraph);
 void EEVEE_render_cache(void *vedata, struct Object *ob, struct RenderEngine *engine, struct Depsgraph *depsgraph);
-void EEVEE_render_draw(EEVEE_Data *vedata, struct RenderEngine *engine, struct RenderResult *render_result, struct RenderLayer *render_layer);
+void EEVEE_render_draw(EEVEE_Data *vedata, struct RenderEngine *engine, struct RenderLayer *render_layer, const struct rcti *rect);
 void EEVEE_render_update_passes(struct RenderEngine *engine, struct Scene *scene, struct ViewLayer *view_layer);
 
 /* Shadow Matrix */
index f2db27f812ff7288f97f575b1ee10f84b8dca29f..e5b32cf2baa9c4d8d49a5cdb9053e645a86764cb 100644 (file)
@@ -33,6 +33,7 @@
 #include "DNA_node_types.h"
 
 #include "BLI_rand.h"
+#include "BLI_rect.h"
 
 #include "DEG_depsgraph_query.h"
 
@@ -152,17 +153,17 @@ void EEVEE_render_cache(
 }
 
 static void eevee_render_result_combined(
-        RenderResult *rr, RenderLayer *rl, const char *viewname,
+        RenderLayer *rl, const char *viewname, const rcti *rect,
         EEVEE_Data *vedata, EEVEE_ViewLayerData *UNUSED(sldata))
 {
        RenderPass *rp = RE_pass_find_by_name(rl, RE_PASSNAME_COMBINED, viewname);
 
        DRW_framebuffer_bind(vedata->stl->effects->final_fb);
-       DRW_framebuffer_read_data(rr->xof, rr->yof, rr->rectx, rr->recty, 4, 0, rp->rect);
+       DRW_framebuffer_read_data(rect->xmin, rect->ymin, BLI_rcti_size_x(rect), BLI_rcti_size_y(rect), 4, 0, rp->rect);
 }
 
 static void eevee_render_result_subsurface(
-        RenderResult *rr, RenderLayer *rl, const char *viewname,
+        RenderLayer *rl, const char *viewname, const rcti *rect,
         EEVEE_Data *vedata, EEVEE_ViewLayerData *UNUSED(sldata))
 {
        const DRWContextState *draw_ctx = DRW_context_state_get();
@@ -180,10 +181,10 @@ static void eevee_render_result_subsurface(
                float render_samples = (float)BKE_collection_engine_property_value_get_int(props, "taa_render_samples");
 
                DRW_framebuffer_bind(vedata->fbl->sss_accum_fb);
-               DRW_framebuffer_read_data(rr->xof, rr->yof, rr->rectx, rr->recty, 3, 1, rp->rect);
+               DRW_framebuffer_read_data(rect->xmin, rect->ymin, BLI_rcti_size_x(rect), BLI_rcti_size_y(rect), 3, 1, rp->rect);
 
                /* This is the accumulated color. Divide by the number of samples. */
-               for (int i = 0; i < rr->rectx * rr->recty * 3; i++) {
+               for (int i = 0; i < rp->rectx * rp->recty * 3; i++) {
                        rp->rect[i] /= render_samples;
                }
        }
@@ -195,10 +196,10 @@ static void eevee_render_result_subsurface(
                float render_samples = (float)BKE_collection_engine_property_value_get_int(props, "taa_render_samples");
 
                DRW_framebuffer_bind(vedata->fbl->sss_accum_fb);
-               DRW_framebuffer_read_data(rr->xof, rr->yof, rr->rectx, rr->recty, 3, 0, rp->rect);
+               DRW_framebuffer_read_data(rect->xmin, rect->ymin, BLI_rcti_size_x(rect), BLI_rcti_size_y(rect), 3, 0, rp->rect);
 
                /* This is the accumulated color. Divide by the number of samples. */
-               for (int i = 0; i < rr->rectx * rr->recty * 3; i++) {
+               for (int i = 0; i < rp->rectx * rp->recty * 3; i++) {
                        rp->rect[i] /= render_samples;
                }
        }
@@ -210,7 +211,7 @@ static void eevee_render_result_subsurface(
 }
 
 static void eevee_render_result_normal(
-        RenderResult *rr, RenderLayer *rl, const char *viewname,
+        RenderLayer *rl, const char *viewname, const rcti *rect,
         EEVEE_Data *vedata, EEVEE_ViewLayerData *UNUSED(sldata))
 {
        const DRWContextState *draw_ctx = DRW_context_state_get();
@@ -225,10 +226,10 @@ static void eevee_render_result_normal(
        if ((view_layer->passflag & SCE_PASS_NORMAL) != 0) {
                RenderPass *rp = RE_pass_find_by_name(rl, RE_PASSNAME_NORMAL, viewname);
 
-               DRW_framebuffer_read_data(rr->xof, rr->yof, rr->rectx, rr->recty, 3, 1, rp->rect);
+               DRW_framebuffer_read_data(rect->xmin, rect->ymin, BLI_rcti_size_x(rect), BLI_rcti_size_y(rect), 3, 1, rp->rect);
 
                /* Convert Eevee encoded normals to Blender normals. */
-               for (int i = 0; i < rr->rectx * rr->recty * 3; i += 3) {
+               for (int i = 0; i < rp->rectx * rp->recty * 3; i += 3) {
                        if (rp->rect[i] == 0.0f && rp->rect[i + 1] == 0.0f) {
                                /* If normal is not correct then do not produce NANs.  */
                                continue;
@@ -251,7 +252,7 @@ static void eevee_render_result_normal(
 }
 
 static void eevee_render_result_z(
-        RenderResult *rr, RenderLayer *rl, const char *viewname,
+        RenderLayer *rl, const char *viewname, const rcti *rect,
         EEVEE_Data *vedata, EEVEE_ViewLayerData *sldata)
 {
        const DRWContextState *draw_ctx = DRW_context_state_get();
@@ -267,12 +268,12 @@ static void eevee_render_result_z(
        if ((view_layer->passflag & SCE_PASS_Z) != 0) {
                RenderPass *rp = RE_pass_find_by_name(rl, RE_PASSNAME_Z, viewname);
 
-               DRW_framebuffer_read_depth(rr->xof, rr->yof, rr->rectx, rr->recty, rp->rect);
+               DRW_framebuffer_read_depth(rect->xmin, rect->ymin, BLI_rcti_size_x(rect), BLI_rcti_size_y(rect), rp->rect);
 
                bool is_persp = DRW_viewport_is_persp_get();
 
                /* Convert ogl depth [0..1] to view Z [near..far] */
-               for (int i = 0; i < rr->rectx * rr->recty; ++i) {
+               for (int i = 0; i < rp->rectx * rp->recty; ++i) {
                        if (rp->rect[i] == 1.0f ) {
                                rp->rect[i] = 1e10f; /* Background */
                        }
@@ -290,7 +291,7 @@ static void eevee_render_result_z(
 }
 
 static void eevee_render_result_mist(
-        RenderResult *rr, RenderLayer *rl, const char *viewname,
+        RenderLayer *rl, const char *viewname, const rcti *rect,
         EEVEE_Data *vedata, EEVEE_ViewLayerData *UNUSED(sldata))
 {
        const DRWContextState *draw_ctx = DRW_context_state_get();
@@ -303,17 +304,17 @@ static void eevee_render_result_mist(
                float render_samples = (float)BKE_collection_engine_property_value_get_int(props, "taa_render_samples");
 
                DRW_framebuffer_bind(vedata->fbl->mist_accum_fb);
-               DRW_framebuffer_read_data(rr->xof, rr->yof, rr->rectx, rr->recty, 1, 0, rp->rect);
+               DRW_framebuffer_read_data(rect->xmin, rect->ymin, BLI_rcti_size_x(rect), BLI_rcti_size_y(rect), 1, 0, rp->rect);
 
                /* This is the accumulated color. Divide by the number of samples. */
-               for (int i = 0; i < rr->rectx * rr->recty; i++) {
+               for (int i = 0; i < rp->rectx * rp->recty; i++) {
                        rp->rect[i] /= render_samples;
                }
        }
 }
 
 static void eevee_render_result_occlusion(
-        RenderResult *rr, RenderLayer *rl, const char *viewname,
+        RenderLayer *rl, const char *viewname, const rcti *rect,
         EEVEE_Data *vedata, EEVEE_ViewLayerData *UNUSED(sldata))
 {
        const DRWContextState *draw_ctx = DRW_context_state_get();
@@ -331,10 +332,10 @@ static void eevee_render_result_occlusion(
                float render_samples = (float)BKE_collection_engine_property_value_get_int(props, "taa_render_samples");
 
                DRW_framebuffer_bind(vedata->fbl->ao_accum_fb);
-               DRW_framebuffer_read_data(rr->xof, rr->yof, rr->rectx, rr->recty, 3, 0, rp->rect);
+               DRW_framebuffer_read_data(rect->xmin, rect->ymin, BLI_rcti_size_x(rect), BLI_rcti_size_y(rect), 3, 0, rp->rect);
 
                /* This is the accumulated color. Divide by the number of samples. */
-               for (int i = 0; i < rr->rectx * rr->recty * 3; i += 3) {
+               for (int i = 0; i < rp->rectx * rp->recty * 3; i += 3) {
                        rp->rect[i] = rp->rect[i + 1] = rp->rect[i+2] = min_ff(1.0f, rp->rect[i] / render_samples);
                }
        }
@@ -368,7 +369,7 @@ static void eevee_render_draw_background(EEVEE_Data *vedata)
        DRW_framebuffer_bind(fbl->main);
 }
 
-void EEVEE_render_draw(EEVEE_Data *vedata, RenderEngine *engine, RenderResult *rr, RenderLayer *rl)
+void EEVEE_render_draw(EEVEE_Data *vedata, RenderEngine *engine, RenderLayer *rl, const rcti *rect)
 {
        const DRWContextState *draw_ctx = DRW_context_state_get();
        ViewLayer *view_layer = draw_ctx->view_layer;
@@ -470,7 +471,7 @@ void EEVEE_render_draw(EEVEE_Data *vedata, RenderEngine *engine, RenderResult *r
                /* Occlusion output */
                EEVEE_occlusion_output_accumulate(sldata, vedata);
                /* Result NORMAL */
-               eevee_render_result_normal(rr, rl, viewname, vedata, sldata);
+               eevee_render_result_normal(rl, viewname, rect, vedata, sldata);
                /* Volumetrics Resolve Opaque */
                EEVEE_volumes_resolve(sldata, vedata);
                /* Mist output */
@@ -478,15 +479,15 @@ void EEVEE_render_draw(EEVEE_Data *vedata, RenderEngine *engine, RenderResult *r
                /* Transparent */
                DRW_draw_pass(psl->transparent_pass);
                /* Result Z */
-               eevee_render_result_z(rr, rl, viewname, vedata, sldata);
+               eevee_render_result_z(rl, viewname, rect, vedata, sldata);
                /* Post Process */
                EEVEE_draw_effects(sldata, vedata);
        }
 
-       eevee_render_result_combined(rr, rl, viewname, vedata, sldata);
-       eevee_render_result_subsurface(rr, rl, viewname, vedata, sldata);
-       eevee_render_result_mist(rr, rl, viewname, vedata, sldata);
-       eevee_render_result_occlusion(rr, rl, viewname, vedata, sldata);
+       eevee_render_result_combined(rl, viewname, rect, vedata, sldata);
+       eevee_render_result_subsurface(rl, viewname, rect, vedata, sldata);
+       eevee_render_result_mist(rl, viewname, rect, vedata, sldata);
+       eevee_render_result_occlusion(rl, viewname, rect, vedata, sldata);
 }
 
 void EEVEE_render_update_passes(RenderEngine *engine, Scene *scene, ViewLayer *view_layer)
index 82ba2922dd02e8153b9ebebbcb52c9bd2fabf310..1a4950bbf97cc77b564b58b4560eacbb1dbb80ff 100644 (file)
@@ -55,6 +55,7 @@
 
 #include "RE_engine.h"
 
+struct rcti;
 struct bContext;
 struct GPUFrameBuffer;
 struct GPUShader;
@@ -140,7 +141,7 @@ typedef struct DrawEngineType {
        void (*view_update)(void *vedata);
        void (*id_update)(void *vedata, struct ID *id);
 
-       void (*render_to_image)(void *vedata, struct RenderEngine *engine, struct RenderResult *result, struct RenderLayer *layer);
+       void (*render_to_image)(void *vedata, struct RenderEngine *engine, struct RenderLayer *layer, const struct rcti *rect);
 } DrawEngineType;
 
 #ifndef __DRW_ENGINE_H__
index a8b59dbc1977001e47c62f866ffbdeafb5e976ab..ac782a9541d5b778d8dfeff49b92e470266a673b 100644 (file)
@@ -3656,6 +3656,9 @@ void DRW_render_to_image(RenderEngine *engine, struct Depsgraph *depsgraph)
        /* Init render result. */
        const float *render_size = DRW_viewport_size_get();
        RenderResult *render_result = RE_engine_begin_result(engine, 0, 0, (int)render_size[0], (int)render_size[1], NULL, NULL);
+       rctf view_rect;
+       rcti render_rect;
+       RE_GetViewPlane(render, &view_rect, &render_rect);
 
        for (RenderView *render_view = render_result->views.first;
             render_view != NULL;
@@ -3673,7 +3676,7 @@ void DRW_render_to_image(RenderEngine *engine, struct Depsgraph *depsgraph)
                         * For rendering depsgraph is to be owned by Render. */
                        DST.draw_ctx.depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);
 
-                       engine_type->draw_engine->render_to_image(data, engine, render_result, render_layer);
+                       engine_type->draw_engine->render_to_image(data, engine, render_layer, &render_rect);
                        DST.buffer_finish_called = false;
                        /* Force cache to reset. */
                        drw_viewport_cache_resize();