Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee/eevee_materials.c
| Show First 20 Lines • Show All 952 Lines • ▼ Show 20 Lines | void EEVEE_material_renderpasses_init(EEVEE_Data *vedata) | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_DIFFUSE_LIGHT) { | if (pd->render_passes & EEVEE_RENDER_PASS_DIFFUSE_LIGHT) { | ||||
| pd->render_passes |= EEVEE_RENDER_PASS_DIFFUSE_COLOR; | pd->render_passes |= EEVEE_RENDER_PASS_DIFFUSE_COLOR; | ||||
| } | } | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_SPECULAR_LIGHT) { | if (pd->render_passes & EEVEE_RENDER_PASS_SPECULAR_LIGHT) { | ||||
| pd->render_passes |= EEVEE_RENDER_PASS_SPECULAR_COLOR; | pd->render_passes |= EEVEE_RENDER_PASS_SPECULAR_COLOR; | ||||
| } | } | ||||
| } | } | ||||
| static void material_renderpass_init(EEVEE_FramebufferList *fbl, | static void material_renderpass_init(GPUTexture **output_tx, const eGPUTextureFormat format) | ||||
| GPUTexture **output_tx, | |||||
| const eGPUTextureFormat format, | |||||
| const bool do_clear) | |||||
| { | { | ||||
| DRW_texture_ensure_fullscreen_2d(output_tx, format, 0); | DRW_texture_ensure_fullscreen_2d(output_tx, format, 0); | ||||
| /* Clear texture. */ | |||||
| if (do_clear) { | |||||
| const float clear[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | |||||
| /* TODO(fclem): replace by GPU_texture_clear once it is fast. */ | |||||
| GPU_framebuffer_texture_attach(fbl->material_accum_fb, *output_tx, 0, 0); | |||||
| GPU_framebuffer_bind(fbl->material_accum_fb); | |||||
| GPU_framebuffer_clear_color(fbl->material_accum_fb, clear); | |||||
| GPU_framebuffer_bind(fbl->main_fb); | |||||
| GPU_framebuffer_texture_detach(fbl->material_accum_fb, *output_tx); | |||||
| } | |||||
| } | } | ||||
| void EEVEE_material_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, uint tot_samples) | void EEVEE_material_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, uint tot_samples) | ||||
| { | { | ||||
| EEVEE_FramebufferList *fbl = vedata->fbl; | EEVEE_FramebufferList *fbl = vedata->fbl; | ||||
| DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); | DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); | ||||
| EEVEE_TextureList *txl = vedata->txl; | EEVEE_TextureList *txl = vedata->txl; | ||||
| EEVEE_StorageList *stl = vedata->stl; | EEVEE_StorageList *stl = vedata->stl; | ||||
| EEVEE_EffectsInfo *effects = stl->effects; | EEVEE_EffectsInfo *effects = stl->effects; | ||||
| EEVEE_PrivateData *pd = stl->g_data; | EEVEE_PrivateData *pd = stl->g_data; | ||||
| /* Should be enough precision for many samples. */ | /* Should be enough precision for many samples. */ | ||||
| const eGPUTextureFormat texture_format = (tot_samples > 128) ? GPU_RGBA32F : GPU_RGBA16F; | const eGPUTextureFormat texture_format = (tot_samples > 128) ? GPU_RGBA32F : GPU_RGBA16F; | ||||
| const bool do_clear = (effects->taa_current_sample == 1); | |||||
| /* Create FrameBuffer. */ | /* Create FrameBuffer. */ | ||||
| GPU_framebuffer_ensure_config(&fbl->material_accum_fb, | GPU_framebuffer_ensure_config(&fbl->material_accum_fb, | ||||
| {GPU_ATTACHMENT_TEXTURE(dtxl->depth), GPU_ATTACHMENT_LEAVE}); | {GPU_ATTACHMENT_TEXTURE(dtxl->depth), GPU_ATTACHMENT_LEAVE}); | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_ENVIRONMENT) { | if (pd->render_passes & EEVEE_RENDER_PASS_ENVIRONMENT) { | ||||
| material_renderpass_init(fbl, &txl->env_accum, texture_format, do_clear); | material_renderpass_init(&txl->env_accum, texture_format); | ||||
| } | } | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_EMIT) { | if (pd->render_passes & EEVEE_RENDER_PASS_EMIT) { | ||||
| material_renderpass_init(fbl, &txl->emit_accum, texture_format, do_clear); | material_renderpass_init(&txl->emit_accum, texture_format); | ||||
| } | } | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_DIFFUSE_COLOR) { | if (pd->render_passes & EEVEE_RENDER_PASS_DIFFUSE_COLOR) { | ||||
| material_renderpass_init(fbl, &txl->diff_color_accum, texture_format, do_clear); | material_renderpass_init(&txl->diff_color_accum, texture_format); | ||||
| } | } | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_DIFFUSE_LIGHT) { | if (pd->render_passes & EEVEE_RENDER_PASS_DIFFUSE_LIGHT) { | ||||
| material_renderpass_init(fbl, &txl->diff_light_accum, texture_format, do_clear); | material_renderpass_init(&txl->diff_light_accum, texture_format); | ||||
| } | } | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_SPECULAR_COLOR) { | if (pd->render_passes & EEVEE_RENDER_PASS_SPECULAR_COLOR) { | ||||
| material_renderpass_init(fbl, &txl->spec_color_accum, texture_format, do_clear); | material_renderpass_init(&txl->spec_color_accum, texture_format); | ||||
| } | } | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_AOV) { | if (pd->render_passes & EEVEE_RENDER_PASS_AOV) { | ||||
| for (int aov_index = 0; aov_index < pd->num_aovs_used; aov_index++) { | for (int aov_index = 0; aov_index < pd->num_aovs_used; aov_index++) { | ||||
| material_renderpass_init(fbl, &txl->aov_surface_accum[aov_index], texture_format, do_clear); | material_renderpass_init(&txl->aov_surface_accum[aov_index], texture_format); | ||||
| } | } | ||||
| } | } | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_SPECULAR_LIGHT) { | if (pd->render_passes & EEVEE_RENDER_PASS_SPECULAR_LIGHT) { | ||||
| material_renderpass_init(fbl, &txl->spec_light_accum, texture_format, do_clear); | material_renderpass_init(&txl->spec_light_accum, texture_format); | ||||
| if (effects->enabled_effects & EFFECT_SSR) { | if (effects->enabled_effects & EFFECT_SSR) { | ||||
| EEVEE_reflection_output_init(sldata, vedata, tot_samples); | EEVEE_reflection_output_init(sldata, vedata, tot_samples); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void material_renderpass_accumulate(EEVEE_FramebufferList *fbl, | static void material_renderpass_accumulate(EEVEE_EffectsInfo *effects, | ||||
| EEVEE_FramebufferList *fbl, | |||||
| DRWPass *renderpass, | DRWPass *renderpass, | ||||
| DRWPass *renderpass2, | DRWPass *renderpass2, | ||||
| EEVEE_PrivateData *pd, | EEVEE_PrivateData *pd, | ||||
| GPUTexture *output_tx, | GPUTexture *output_tx, | ||||
| struct GPUUniformBuf *renderpass_option_ubo) | struct GPUUniformBuf *renderpass_option_ubo) | ||||
| { | { | ||||
| GPU_framebuffer_texture_attach(fbl->material_accum_fb, output_tx, 0, 0); | GPU_framebuffer_texture_attach(fbl->material_accum_fb, output_tx, 0, 0); | ||||
| GPU_framebuffer_bind(fbl->material_accum_fb); | GPU_framebuffer_bind(fbl->material_accum_fb); | ||||
| if (effects->taa_current_sample == 1) { | |||||
| const float clear[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | |||||
| GPU_framebuffer_clear_color(fbl->material_accum_fb, clear); | |||||
| } | |||||
| pd->renderpass_ubo = renderpass_option_ubo; | pd->renderpass_ubo = renderpass_option_ubo; | ||||
| DRW_draw_pass(renderpass); | DRW_draw_pass(renderpass); | ||||
| if (renderpass2) { | if (renderpass2) { | ||||
| DRW_draw_pass(renderpass2); | DRW_draw_pass(renderpass2); | ||||
| } | } | ||||
| GPU_framebuffer_texture_detach(fbl->material_accum_fb, output_tx); | GPU_framebuffer_texture_detach(fbl->material_accum_fb, output_tx); | ||||
| } | } | ||||
| void EEVEE_material_output_accumulate(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) | void EEVEE_material_output_accumulate(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) | ||||
| { | { | ||||
| EEVEE_FramebufferList *fbl = vedata->fbl; | EEVEE_FramebufferList *fbl = vedata->fbl; | ||||
| EEVEE_PassList *psl = vedata->psl; | EEVEE_PassList *psl = vedata->psl; | ||||
| EEVEE_PrivateData *pd = vedata->stl->g_data; | EEVEE_PrivateData *pd = vedata->stl->g_data; | ||||
| EEVEE_EffectsInfo *effects = vedata->stl->effects; | EEVEE_EffectsInfo *effects = vedata->stl->effects; | ||||
| EEVEE_TextureList *txl = vedata->txl; | EEVEE_TextureList *txl = vedata->txl; | ||||
| if (fbl->material_accum_fb != NULL) { | if (fbl->material_accum_fb != NULL) { | ||||
| DRWPass *material_accum_ps = psl->material_accum_ps; | DRWPass *material_accum_ps = psl->material_accum_ps; | ||||
| DRWPass *background_accum_ps = psl->background_accum_ps; | DRWPass *background_accum_ps = psl->background_accum_ps; | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_ENVIRONMENT) { | if (pd->render_passes & EEVEE_RENDER_PASS_ENVIRONMENT) { | ||||
| material_renderpass_accumulate( | material_renderpass_accumulate(effects, | ||||
| fbl, background_accum_ps, NULL, pd, txl->env_accum, sldata->renderpass_ubo.environment); | fbl, | ||||
| background_accum_ps, | |||||
| NULL, | |||||
| pd, | |||||
| txl->env_accum, | |||||
| sldata->renderpass_ubo.environment); | |||||
| } | } | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_EMIT) { | if (pd->render_passes & EEVEE_RENDER_PASS_EMIT) { | ||||
| material_renderpass_accumulate( | material_renderpass_accumulate( | ||||
| fbl, material_accum_ps, NULL, pd, txl->emit_accum, sldata->renderpass_ubo.emit); | effects, fbl, material_accum_ps, NULL, pd, txl->emit_accum, sldata->renderpass_ubo.emit); | ||||
| } | } | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_DIFFUSE_COLOR) { | if (pd->render_passes & EEVEE_RENDER_PASS_DIFFUSE_COLOR) { | ||||
| material_renderpass_accumulate(fbl, | material_renderpass_accumulate(effects, | ||||
| fbl, | |||||
| material_accum_ps, | material_accum_ps, | ||||
| NULL, | NULL, | ||||
| pd, | pd, | ||||
| txl->diff_color_accum, | txl->diff_color_accum, | ||||
| sldata->renderpass_ubo.diff_color); | sldata->renderpass_ubo.diff_color); | ||||
| } | } | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_DIFFUSE_LIGHT) { | if (pd->render_passes & EEVEE_RENDER_PASS_DIFFUSE_LIGHT) { | ||||
| material_renderpass_accumulate(fbl, | material_renderpass_accumulate(effects, | ||||
| fbl, | |||||
| material_accum_ps, | material_accum_ps, | ||||
| NULL, | NULL, | ||||
| pd, | pd, | ||||
| txl->diff_light_accum, | txl->diff_light_accum, | ||||
| sldata->renderpass_ubo.diff_light); | sldata->renderpass_ubo.diff_light); | ||||
| if (effects->enabled_effects & EFFECT_SSS) { | if (effects->enabled_effects & EFFECT_SSS) { | ||||
| EEVEE_subsurface_output_accumulate(sldata, vedata); | EEVEE_subsurface_output_accumulate(sldata, vedata); | ||||
| } | } | ||||
| } | } | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_SPECULAR_COLOR) { | if (pd->render_passes & EEVEE_RENDER_PASS_SPECULAR_COLOR) { | ||||
| bool prev_ssr = sldata->common_data.ssr_toggle; | bool prev_ssr = sldata->common_data.ssr_toggle; | ||||
| if (prev_ssr) { | if (prev_ssr) { | ||||
| /* We need to disable ssr here so output radiance is not directed to the ssr buffer. */ | /* We need to disable ssr here so output radiance is not directed to the ssr buffer. */ | ||||
| sldata->common_data.ssr_toggle = false; | sldata->common_data.ssr_toggle = false; | ||||
| GPU_uniformbuf_update(sldata->common_ubo, &sldata->common_data); | GPU_uniformbuf_update(sldata->common_ubo, &sldata->common_data); | ||||
| } | } | ||||
| material_renderpass_accumulate(fbl, | material_renderpass_accumulate(effects, | ||||
| fbl, | |||||
| material_accum_ps, | material_accum_ps, | ||||
| NULL, | NULL, | ||||
| pd, | pd, | ||||
| txl->spec_color_accum, | txl->spec_color_accum, | ||||
| sldata->renderpass_ubo.spec_color); | sldata->renderpass_ubo.spec_color); | ||||
| if (prev_ssr) { | if (prev_ssr) { | ||||
| sldata->common_data.ssr_toggle = prev_ssr; | sldata->common_data.ssr_toggle = prev_ssr; | ||||
| GPU_uniformbuf_update(sldata->common_ubo, &sldata->common_data); | GPU_uniformbuf_update(sldata->common_ubo, &sldata->common_data); | ||||
| } | } | ||||
| } | } | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_SPECULAR_LIGHT) { | if (pd->render_passes & EEVEE_RENDER_PASS_SPECULAR_LIGHT) { | ||||
| material_renderpass_accumulate(fbl, | material_renderpass_accumulate(effects, | ||||
| fbl, | |||||
| material_accum_ps, | material_accum_ps, | ||||
| NULL, | NULL, | ||||
| pd, | pd, | ||||
| txl->spec_light_accum, | txl->spec_light_accum, | ||||
| sldata->renderpass_ubo.spec_light); | sldata->renderpass_ubo.spec_light); | ||||
| if (effects->enabled_effects & EFFECT_SSR) { | if (effects->enabled_effects & EFFECT_SSR) { | ||||
| EEVEE_reflection_output_accumulate(sldata, vedata); | EEVEE_reflection_output_accumulate(sldata, vedata); | ||||
| } | } | ||||
| } | } | ||||
| if (pd->render_passes & EEVEE_RENDER_PASS_AOV) { | if (pd->render_passes & EEVEE_RENDER_PASS_AOV) { | ||||
| for (int aov_index = 0; aov_index < pd->num_aovs_used; aov_index++) { | for (int aov_index = 0; aov_index < pd->num_aovs_used; aov_index++) { | ||||
| material_renderpass_accumulate(fbl, | material_renderpass_accumulate(effects, | ||||
| fbl, | |||||
| material_accum_ps, | material_accum_ps, | ||||
| background_accum_ps, | background_accum_ps, | ||||
| pd, | pd, | ||||
| txl->aov_surface_accum[aov_index], | txl->aov_surface_accum[aov_index], | ||||
| sldata->renderpass_ubo.aovs[aov_index]); | sldata->renderpass_ubo.aovs[aov_index]); | ||||
| } | } | ||||
| } | } | ||||
| /* Free unused aov textures. */ | /* Free unused aov textures. */ | ||||
| Show All 11 Lines | |||||