Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/eevee_renderpasses.c
- This file was added.
| /* | |||||
| * This program is free software; you can redistribute it and/or | |||||
| * modify it under the terms of the GNU General Public License | |||||
| * as published by the Free Software Foundation; either version 2 | |||||
| * of the License, or (at your option) any later version. | |||||
| * | |||||
| * This program is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with this program; if not, write to the Free Software Foundation, | |||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
| * | |||||
| * Copyright 2019, Blender Foundation. | |||||
| */ | |||||
| /** \file | |||||
| * \ingroup draw_engine | |||||
| */ | |||||
| #include "DRW_engine.h" | |||||
| #include "DRW_render.h" | |||||
| #include "BLI_string_utils.h" | |||||
| #include "eevee_private.h" | |||||
| extern char datatoc_common_view_lib_glsl[]; | |||||
| extern char datatoc_common_uniforms_lib_glsl[]; | |||||
| extern char datatoc_bsdf_common_lib_glsl[]; | |||||
| extern char datatoc_renderpass_postprocess_frag_glsl[]; | |||||
| static struct { | |||||
| struct GPUShader *postprocess_sh; | |||||
| } e_data = {NULL}; /* Engine data */ | |||||
| void EEVEE_renderpass_init(EEVEE_Data *vedata) | |||||
| { | |||||
| // const DRWContextState *draw_ctx = DRW_context_state_get(); | |||||
| EEVEE_FramebufferList *fbl = vedata->fbl; | |||||
| EEVEE_TextureList *txl = vedata->txl; | |||||
| EEVEE_PassList *psl = vedata->psl; | |||||
| if (e_data.postprocess_sh == NULL) { | |||||
| char *frag_str = BLI_string_joinN(datatoc_common_view_lib_glsl, | |||||
| datatoc_common_uniforms_lib_glsl, | |||||
| datatoc_bsdf_common_lib_glsl, | |||||
| datatoc_renderpass_postprocess_frag_glsl); | |||||
| e_data.postprocess_sh = DRW_shader_create_fullscreen(frag_str, NULL); | |||||
| MEM_freeN(frag_str); | |||||
| } | |||||
| /* Create FrameBuffer. */ | |||||
| /* Should be enough to store the data needs for a single pass. | |||||
| * Some passes will use less, but it is only relevant for final renderings and | |||||
| * when renderpasses other than `SCE_PASS_COMBINED` are requested */ | |||||
| DRW_texture_ensure_fullscreen_2d(&txl->renderpass, GPU_RGBA16F, 0); | |||||
| GPU_framebuffer_ensure_config(&fbl->renderpass_fb, | |||||
jbakker: Remove comment, is relevant for the next phase, not the current patch | |||||
| {GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(txl->renderpass)}); | |||||
| /* Create Pass and shgroup. */ | |||||
| DRW_PASS_CREATE(psl->renderpass_pass, DRW_STATE_WRITE_COLOR); | |||||
| } | |||||
| /* Postprocess data to construct a specific renderpass | |||||
| * | |||||
| * this method will create a shading group for the post processing and will also | |||||
Done Inline ActionsAdd some documentation about the usage and expected results. jbakker: Add some documentation about the usage and expected results. | |||||
| * draw the shading group. | |||||
| * | |||||
| * After calling this function, the `target_fb` will be the active framebuffer. | |||||
| * the color0 attachment contains the result of the requested renderpass. */ | |||||
| void EEVEE_renderpass_postprocess(EEVEE_ViewLayerData *sldata, | |||||
| EEVEE_Data *vedata, | |||||
| eScenePassType renderpass_type, | |||||
| GPUFrameBuffer *target_fb, | |||||
| int current_sample) | |||||
| { | |||||
| EEVEE_PassList *psl = vedata->psl; | |||||
| EEVEE_TextureList *txl = vedata->txl; | |||||
| EEVEE_StorageList *stl = vedata->stl; | |||||
| EEVEE_EffectsInfo *effects = stl->effects; | |||||
| DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); | |||||
| DRWShadingGroup *shgrp = DRW_shgroup_create(e_data.postprocess_sh, psl->renderpass_pass); | |||||
| DRW_shgroup_uniform_int_copy(shgrp, "renderpassType", renderpass_type); | |||||
| switch (renderpass_type) { | |||||
| case SCE_PASS_Z: { | |||||
| DRW_shgroup_uniform_block(shgrp, "common_block", sldata->common_ubo); | |||||
| DRW_shgroup_uniform_texture_ref(shgrp, "depthBuffer", &dtxl->depth); | |||||
| break; | |||||
| } | |||||
| case SCE_PASS_AO: { | |||||
| DRW_shgroup_uniform_texture_ref(shgrp, "inputBuffer", &txl->ao_accum); | |||||
| DRW_shgroup_uniform_int_copy(shgrp, "currentSample", current_sample); | |||||
| break; | |||||
| } | |||||
| case SCE_PASS_NORMAL: { | |||||
| DRW_shgroup_uniform_texture_ref(shgrp, "inputBuffer", &effects->ssr_normal_input); | |||||
| break; | |||||
| } | |||||
| case SCE_PASS_MIST: { | |||||
| DRW_shgroup_uniform_texture_ref(shgrp, "inputBuffer", &txl->mist_accum); | |||||
| DRW_shgroup_uniform_int_copy(shgrp, "currentSample", current_sample); | |||||
| break; | |||||
| } | |||||
| case SCE_PASS_SUBSURFACE_DIRECT: { | |||||
| DRW_shgroup_uniform_texture_ref(shgrp, "inputBuffer", &txl->sss_dir_accum); | |||||
| DRW_shgroup_uniform_int_copy(shgrp, "currentSample", current_sample); | |||||
| break; | |||||
| } | |||||
| case SCE_PASS_SUBSURFACE_COLOR: { | |||||
| DRW_shgroup_uniform_texture_ref(shgrp, "inputBuffer", &txl->sss_col_accum); | |||||
| DRW_shgroup_uniform_int_copy(shgrp, "currentSample", current_sample); | |||||
| break; | |||||
| } | |||||
| default: { | |||||
| break; | |||||
| } | |||||
| } | |||||
Done Inline Actionslatest jbakker: latest | |||||
| DRW_shgroup_call(shgrp, DRW_cache_fullscreen_quad_get(), NULL); | |||||
| GPU_framebuffer_bind(target_fb); | |||||
| // only draw the lastest added shading group. | |||||
| DRW_draw_pass_subset(psl->renderpass_pass, shgrp, shgrp); | |||||
| } | |||||
| void EEVEE_renderpass_free(void) | |||||
| { | |||||
| DRW_SHADER_FREE_SAFE(e_data.postprocess_sh); | |||||
| } | |||||
Remove comment, is relevant for the next phase, not the current patch