diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-01-29 23:59:34 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-01-30 00:00:15 +0300 |
commit | 376d42304b716da2f9bda8b55c539d39ac416281 (patch) | |
tree | b1ee8e832b10788527f30b72d478569e5e795b4f | |
parent | 0f93d676176bb1dd7e74d032e7905f2d967e3ac8 (diff) |
Eevee: Add Z pass render result.
-rw-r--r-- | release/scripts/startup/bl_ui/properties_view_layer.py | 20 | ||||
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_render.c | 34 | ||||
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 1 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 8 |
4 files changed, 63 insertions, 0 deletions
diff --git a/release/scripts/startup/bl_ui/properties_view_layer.py b/release/scripts/startup/bl_ui/properties_view_layer.py index 291b68b41d9..d4aa1a6070a 100644 --- a/release/scripts/startup/bl_ui/properties_view_layer.py +++ b/release/scripts/startup/bl_ui/properties_view_layer.py @@ -450,6 +450,25 @@ class VIEWLAYER_PT_eevee_indirect_lighting(ViewLayerButtonsPanel, Panel): col.template_override_property(layer_props, scene_props, "gi_visibility_resolution") +class VIEWLAYER_PT_eevee_layer_passes(ViewLayerButtonsPanel, Panel): + bl_label = "Passes" + bl_options = {'DEFAULT_CLOSED'} + COMPAT_ENGINES = {'BLENDER_EEVEE'} + + def draw(self, context): + layout = self.layout + + scene = context.scene + rd = scene.render + view_layer = scene.view_layers.active + + split = layout.split() + + col = split.column() + col.prop(view_layer, "use_pass_combined") + col.prop(view_layer, "use_pass_z") + + classes = ( VIEWLAYER_UL_viewlayers, VIEWLAYER_PT_layers, @@ -466,6 +485,7 @@ classes = ( VIEWLAYER_PT_eevee_motion_blur, VIEWLAYER_PT_eevee_depth_of_field, VIEWLAYER_PT_eevee_bloom, + VIEWLAYER_PT_eevee_layer_passes, ) if __name__ == "__main__": # only for live edit. diff --git a/source/blender/draw/engines/eevee/eevee_render.c b/source/blender/draw/engines/eevee/eevee_render.c index 54c20e661c4..a020887e420 100644 --- a/source/blender/draw/engines/eevee/eevee_render.c +++ b/source/blender/draw/engines/eevee/eevee_render.c @@ -228,11 +228,19 @@ void EEVEE_render_draw(EEVEE_Data *vedata, struct RenderEngine *UNUSED(engine), void EEVEE_render_output(EEVEE_Data *vedata, RenderEngine *engine, struct Depsgraph *UNUSED(depsgraph)) { + const DRWContextState *draw_ctx = DRW_context_state_get(); + ViewLayer *view_layer = draw_ctx->view_layer; + DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); + EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure(); + EEVEE_FramebufferList *fbl = vedata->fbl; EEVEE_StorageList *stl = vedata->stl; + EEVEE_PrivateData *g_data = stl->g_data; + EEVEE_CommonUniformBuffer *common_data = &sldata->common_data; const char *viewname = NULL; const float *render_size = DRW_viewport_size_get(); + /* Combined */ RenderResult *rr = RE_engine_begin_result(engine, 0, 0, (int)render_size[0], (int)render_size[1], NULL, viewname); RenderLayer *rl = rr->layers.first; RenderPass *rp = RE_pass_find_by_name(rl, RE_PASSNAME_COMBINED, viewname); @@ -240,5 +248,31 @@ void EEVEE_render_output(EEVEE_Data *vedata, RenderEngine *engine, struct Depsgr DRW_framebuffer_bind(stl->effects->final_fb); DRW_framebuffer_read_data(0, 0, (int)render_size[0], (int)render_size[1], 4, 0, rp->rect); + if (view_layer->passflag & SCE_PASS_Z) { + rp = RE_pass_find_by_name(rl, RE_PASSNAME_Z, viewname); + + DRW_framebuffer_texture_attach(fbl->main, dtxl->depth, 0, 0); + DRW_framebuffer_bind(fbl->main); + DRW_framebuffer_read_depth(0, 0, (int)render_size[0], (int)render_size[1], 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 < (int)render_size[0] * (int)render_size[1]; ++i) { + if (rp->rect[i] == 1.0f ) { + rp->rect[i] = 1e10f; /* Background */ + } + else { + if (is_persp) { + rp->rect[i] = rp->rect[i] * 2.0f - 1.0f; + rp->rect[i] = g_data->winmat[3][2] / (rp->rect[i] + g_data->winmat[2][2]); + } + else { + rp->rect[i] = -common_data->view_vecs[0][2] + rp->rect[i] * -common_data->view_vecs[1][2]; + } + } + } + } + RE_engine_end_result(engine, rr, false, false, false); }
\ No newline at end of file diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index a9ab2d2cf0e..528495b8710 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -238,6 +238,7 @@ void DRW_framebuffer_init( void DRW_framebuffer_bind(struct GPUFrameBuffer *fb); void DRW_framebuffer_clear(bool color, bool depth, bool stencil, float clear_col[4], float clear_depth); void DRW_framebuffer_read_data(int x, int y, int w, int h, int channels, int slot, float *data); +void DRW_framebuffer_read_depth(int x, int y, int w, int h, float *data); void DRW_framebuffer_texture_attach(struct GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int mip); void DRW_framebuffer_texture_layer_attach(struct GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int layer, int mip); void DRW_framebuffer_cubeface_attach(struct GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int face, int mip); diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index d4868fd3313..55195b88c05 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2415,6 +2415,14 @@ void DRW_framebuffer_read_data(int x, int y, int w, int h, int channels, int slo glReadPixels(x, y, w, h, type, GL_FLOAT, data); } +void DRW_framebuffer_read_depth(int x, int y, int w, int h, float *data) +{ + GLenum type = GL_DEPTH_COMPONENT; + + glReadBuffer(GL_COLOR_ATTACHMENT0); /* This is OK! */ + glReadPixels(x, y, w, h, type, GL_FLOAT, data); +} + void DRW_framebuffer_texture_attach(struct GPUFrameBuffer *fb, GPUTexture *tex, int slot, int mip) { GPU_framebuffer_texture_attach(fb, tex, slot, mip); |