Eevee: Add Z pass render result.
This commit is contained in:
parent
0f93d67617
commit
376d42304b
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue