diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-04-30 23:23:54 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-05-01 13:09:18 +0300 |
commit | e66629c128258a325ef7d898fb352e3d2552bbcb (patch) | |
tree | 1594b47733dab7e81bf6841549c591df5d4e550c /source/blender/draw/engines/eevee/eevee_materials.c | |
parent | b581f1929287381fe9c2761dc514d5bfa7cbe41c (diff) |
Eevee: Lookdev: Cleanup implementation & support for Bloom and TAA
Make Lookdev works with bloom and TAA by rendering it before TAA and fixing
the motion vectors of the lookdev balls.
Rework Lookdev to remove much of its complexity. Use simpler matrices with
more understandable setup code.
Diffstat (limited to 'source/blender/draw/engines/eevee/eevee_materials.c')
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_materials.c | 112 |
1 files changed, 37 insertions, 75 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c index 8d90a2d29cc..fa767039029 100644 --- a/source/blender/draw/engines/eevee/eevee_materials.c +++ b/source/blender/draw/engines/eevee/eevee_materials.c @@ -336,7 +336,10 @@ static char *eevee_get_defines(int options) BLI_dynstr_append(ds, "#define USE_ALPHA_BLEND_VOLUMETRICS\n"); } if ((options & VAR_MAT_LOOKDEV) != 0) { + /* Auto config shadow method. Avoid more permutation. */ + BLI_assert((options & (VAR_MAT_VSM | VAR_MAT_ESM)) == 0); BLI_dynstr_append(ds, "#define LOOKDEV\n"); + BLI_dynstr_append(ds, "#define SHADOW_ESM\n"); } str = BLI_dynstr_get_cstring(ds); @@ -995,42 +998,11 @@ static struct DRWShadingGroup *EEVEE_default_shading_group_get(EEVEE_ViewLayerDa } } -/** - * Create a default shading group inside the lookdev pass without standard uniforms. - */ -static struct DRWShadingGroup *EEVEE_lookdev_shading_group_get(EEVEE_ViewLayerData *sldata, - EEVEE_Data *vedata, - bool use_ssr, - int shadow_method) -{ - static int ssr_id; - ssr_id = (use_ssr) ? 1 : -1; - int options = VAR_MAT_MESH | VAR_MAT_LOOKDEV; - - options |= eevee_material_shadow_option(shadow_method); - - if (e_data.default_lit[options] == NULL) { - create_default_shader(options); - } - - if (vedata->psl->lookdev_pass == NULL) { - DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS | - DRW_STATE_CULL_BACK; - vedata->psl->lookdev_pass = DRW_pass_create("LookDev Pass", state); - - DRWShadingGroup *shgrp = DRW_shgroup_create(e_data.default_lit[options], - vedata->psl->lookdev_pass); - /* XXX / WATCH: This creates non persistent binds for the ubos and textures. - * But it's currently OK because the following shgroups does not add any bind. */ - add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL, true, true, false, false, false); - } - - return DRW_shgroup_create(e_data.default_lit[options], vedata->psl->lookdev_pass); -} void EEVEE_materials_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) { EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl; EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl; + const DRWContextState *draw_ctx = DRW_context_state_get(); /* Create Material Ghash */ { @@ -1044,16 +1016,13 @@ void EEVEE_materials_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) struct GPUBatch *geom = DRW_cache_fullscreen_quad_get(); DRWShadingGroup *grp = NULL; - const DRWContextState *draw_ctx = DRW_context_state_get(); Scene *scene = draw_ctx->scene; World *wo = scene->world; const float *col = G_draw.block.colorBackground; - /* LookDev */ EEVEE_lookdev_cache_init( vedata, &grp, psl->background_pass, stl->g_data->background_alpha, wo, NULL); - /* END */ if (!grp && wo) { col = &wo->horr; @@ -1184,6 +1153,39 @@ void EEVEE_materials_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) DRW_shgroup_uniform_vec3(grp, "offsets", e_data.noise_offsets, 1); DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL); } + + if (LOOK_DEV_OVERLAY_ENABLED(draw_ctx->v3d)) { + DRWShadingGroup *shgrp; + + struct GPUBatch *sphere = DRW_cache_sphere_get(); + static float color_chrome[3] = {1.0f, 1.0f, 1.0f}; + static float color_diffuse[3] = {0.8f, 0.8f, 0.8f}; + int options = VAR_MAT_MESH | VAR_MAT_LOOKDEV; + + if (e_data.default_lit[options] == NULL) { + create_default_shader(options); + } + + DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS | + DRW_STATE_CULL_BACK; + + psl->lookdev_diffuse_pass = DRW_pass_create("LookDev Diffuse Pass", state); + shgrp = DRW_shgroup_create(e_data.default_lit[options], psl->lookdev_diffuse_pass); + add_standard_uniforms(shgrp, sldata, vedata, NULL, NULL, true, true, false, false, false); + DRW_shgroup_uniform_vec3(shgrp, "basecol", color_diffuse, 1); + DRW_shgroup_uniform_float_copy(shgrp, "metallic", 0.0f); + DRW_shgroup_uniform_float_copy(shgrp, "specular", 0.5f); + DRW_shgroup_uniform_float_copy(shgrp, "roughness", 1.0f); + DRW_shgroup_call_add(shgrp, sphere, NULL); + + psl->lookdev_glossy_pass = DRW_pass_create("LookDev Glossy Pass", state); + shgrp = DRW_shgroup_create(e_data.default_lit[options], psl->lookdev_glossy_pass); + add_standard_uniforms(shgrp, sldata, vedata, NULL, NULL, true, true, false, false, false); + DRW_shgroup_uniform_vec3(shgrp, "basecol", color_chrome, 1); + DRW_shgroup_uniform_float_copy(shgrp, "metallic", 1.0f); + DRW_shgroup_uniform_float_copy(shgrp, "roughness", 0.0f); + DRW_shgroup_call_add(shgrp, sphere, NULL); + } } #define ADD_SHGROUP_CALL(shgrp, ob, ma, geom, oedata) \ @@ -1926,46 +1928,6 @@ void EEVEE_materials_cache_finish(EEVEE_Data *vedata) { EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl; - /* Look-Dev */ - const DRWContextState *draw_ctx = DRW_context_state_get(); - const View3D *v3d = draw_ctx->v3d; - if (LOOK_DEV_OVERLAY_ENABLED(v3d)) { - EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure(); - EEVEE_LightsInfo *linfo = sldata->lights; - struct GPUBatch *sphere = DRW_cache_sphere_get(); - static float mat1[4][4]; - static float color[3] = {0.8f, 0.8f, 0.8f}; - static float metallic_on = 1.0f; - static float metallic_off = 0.00f; - static float specular_off = 0.5f; - static float specular_on = 1.0f; - static float roughness_off = 0.05f; - static float roughness_on = 1.00f; - - float view_mat[4][4]; - DRW_viewport_matrix_get(view_mat, DRW_MAT_VIEWINV); - - DRWShadingGroup *shgrp = EEVEE_lookdev_shading_group_get( - sldata, vedata, false, linfo->shadow_method); - DRW_shgroup_uniform_vec3(shgrp, "basecol", color, 1); - DRW_shgroup_uniform_float(shgrp, "metallic", &metallic_on, 1); - DRW_shgroup_uniform_float(shgrp, "specular", &specular_on, 1); - DRW_shgroup_uniform_float(shgrp, "roughness", &roughness_off, 1); - unit_m4(mat1); - mul_m4_m4m4(mat1, mat1, view_mat); - translate_m4(mat1, -1.5f, 0.0f, -5.0f); - DRW_shgroup_call_add(shgrp, sphere, mat1); - - shgrp = EEVEE_lookdev_shading_group_get(sldata, vedata, false, linfo->shadow_method); - DRW_shgroup_uniform_vec3(shgrp, "basecol", color, 1); - DRW_shgroup_uniform_float(shgrp, "metallic", &metallic_off, 1); - DRW_shgroup_uniform_float(shgrp, "specular", &specular_off, 1); - DRW_shgroup_uniform_float(shgrp, "roughness", &roughness_on, 1); - translate_m4(mat1, 3.0f, 0.0f, 0.0f); - DRW_shgroup_call_add(shgrp, sphere, mat1); - } - /* END */ - BLI_ghash_free(stl->g_data->material_hash, NULL, MEM_freeN); } |