diff options
9 files changed, 124 insertions, 22 deletions
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 48d502eb342..0da7fd79435 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -122,6 +122,8 @@ data_to_c_simple(engines/eevee/shaders/lightprobe_filter_glossy_frag.glsl SRC) data_to_c_simple(engines/eevee/shaders/lightprobe_filter_diffuse_frag.glsl SRC) data_to_c_simple(engines/eevee/shaders/lightprobe_geom.glsl SRC) data_to_c_simple(engines/eevee/shaders/lightprobe_vert.glsl SRC) +data_to_c_simple(engines/eevee/shaders/lightprobe_grid_display_frag.glsl SRC) +data_to_c_simple(engines/eevee/shaders/lightprobe_grid_display_vert.glsl SRC) data_to_c_simple(engines/eevee/shaders/lit_surface_frag.glsl SRC) data_to_c_simple(engines/eevee/shaders/lit_surface_vert.glsl SRC) data_to_c_simple(engines/eevee/shaders/effect_bloom_frag.glsl SRC) @@ -138,6 +140,7 @@ data_to_c_simple(engines/eevee/shaders/shadow_store_vert.glsl SRC) data_to_c_simple(engines/eevee/shaders/bsdf_lut_frag.glsl SRC) data_to_c_simple(engines/eevee/shaders/bsdf_direct_lib.glsl SRC) data_to_c_simple(engines/eevee/shaders/bsdf_common_lib.glsl SRC) +data_to_c_simple(engines/eevee/shaders/irradiance_lib.glsl SRC) data_to_c_simple(engines/eevee/shaders/bsdf_sampling_lib.glsl SRC) data_to_c_simple(engines/eevee/shaders/ltc_lib.glsl SRC) diff --git a/source/blender/draw/engines/eevee/eevee_engine.c b/source/blender/draw/engines/eevee/eevee_engine.c index 915a0065b60..ef8f1a73c9e 100644 --- a/source/blender/draw/engines/eevee/eevee_engine.c +++ b/source/blender/draw/engines/eevee/eevee_engine.c @@ -115,10 +115,11 @@ static void EEVEE_cache_populate(void *vedata, Object *ob) static void EEVEE_cache_finish(void *vedata) { EEVEE_SceneLayerData *sldata = EEVEE_scene_layer_data_get(); + EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl; EEVEE_materials_cache_finish(vedata); EEVEE_lights_cache_finish(sldata); - EEVEE_lightprobes_cache_finish(sldata); + EEVEE_lightprobes_cache_finish(sldata, psl); } static void EEVEE_draw_scene(void *vedata) @@ -149,6 +150,7 @@ static void EEVEE_draw_scene(void *vedata) DRW_draw_pass(psl->depth_pass_cull); /* Shading pass */ + DRW_draw_pass(psl->probe_display); DRW_draw_pass(psl->default_pass); DRW_draw_pass(psl->default_flat_pass); DRW_draw_pass(psl->default_hair_pass); diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c b/source/blender/draw/engines/eevee/eevee_lightprobes.c index 7776a9f938f..f359ff2c3f7 100644 --- a/source/blender/draw/engines/eevee/eevee_lightprobes.c +++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c @@ -55,6 +55,7 @@ static struct { struct GPUShader *probe_default_sh; struct GPUShader *probe_filter_glossy_sh; struct GPUShader *probe_filter_diffuse_sh; + struct GPUShader *probe_grid_display_sh; struct GPUTexture *hammersley; @@ -68,6 +69,9 @@ extern char datatoc_lightprobe_filter_glossy_frag_glsl[]; extern char datatoc_lightprobe_filter_diffuse_frag_glsl[]; extern char datatoc_lightprobe_geom_glsl[]; extern char datatoc_lightprobe_vert_glsl[]; +extern char datatoc_lightprobe_grid_display_frag_glsl[]; +extern char datatoc_lightprobe_grid_display_vert_glsl[]; +extern char datatoc_irradiance_lib_glsl[]; extern char datatoc_bsdf_common_lib_glsl[]; extern char datatoc_bsdf_sampling_lib_glsl[]; @@ -148,6 +152,25 @@ void EEVEE_lightprobes_init(EEVEE_SceneLayerData *sldata) MEM_freeN(shader_str); + ds_frag = BLI_dynstr_new(); + BLI_dynstr_append(ds_frag, datatoc_irradiance_lib_glsl); + BLI_dynstr_append(ds_frag, datatoc_lightprobe_grid_display_frag_glsl); + shader_str = BLI_dynstr_get_cstring(ds_frag); + BLI_dynstr_free(ds_frag); + + e_data.probe_grid_display_sh = DRW_shader_create( + datatoc_lightprobe_grid_display_vert_glsl, NULL, shader_str, +#if defined(IRRADIANCE_SH_L2) + "#define IRRADIANCE_SH_L2\n" +#elif defined(IRRADIANCE_CUBEMAP) + "#define IRRADIANCE_CUBEMAP\n" +#elif defined(IRRADIANCE_HL2) + "#define IRRADIANCE_HL2\n" +#endif + ); + + MEM_freeN(shader_str); + e_data.hammersley = create_hammersley_sample_texture(1024); } @@ -227,10 +250,6 @@ void EEVEE_lightprobes_cache_init(EEVEE_SceneLayerData *sldata, EEVEE_PassList * } { - psl->probe_meshes = DRW_pass_create("LightProbe Meshes", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS); - } - - { psl->probe_glossy_compute = DRW_pass_create("LightProbe Glossy Compute", DRW_STATE_WRITE_COLOR); struct Batch *geom = DRW_cache_fullscreen_quad_get(); @@ -262,12 +281,17 @@ void EEVEE_lightprobes_cache_init(EEVEE_SceneLayerData *sldata, EEVEE_PassList * DRW_shgroup_uniform_float(grp, "invSampleCount", &sldata->probes->invsamples_ct, 1); DRW_shgroup_uniform_float(grp, "lodFactor", &sldata->probes->lodfactor, 1); DRW_shgroup_uniform_float(grp, "lodMax", &sldata->probes->lodmax, 1); + DRW_shgroup_uniform_texture(grp, "texHammersley", e_data.hammersley); #endif DRW_shgroup_uniform_texture(grp, "probeHdr", sldata->probe_rt); struct Batch *geom = DRW_cache_fullscreen_quad_get(); DRW_shgroup_call_add(grp, geom, NULL); } + + { + psl->probe_display = DRW_pass_create("LightProbe Display", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS); + } } void EEVEE_lightprobes_cache_add(EEVEE_SceneLayerData *sldata, Object *ob) @@ -303,7 +327,7 @@ void EEVEE_lightprobes_cache_add(EEVEE_SceneLayerData *sldata, Object *ob) } } -static void EEVEE_lightprobes_updates(EEVEE_SceneLayerData *sldata) +static void EEVEE_lightprobes_updates(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl) { EEVEE_LightProbesInfo *pinfo = sldata->probes; Object *ob; @@ -349,7 +373,8 @@ static void EEVEE_lightprobes_updates(EEVEE_SceneLayerData *sldata) egrid->offset = offset; /* Set offset for the next grid */ - offset += probe->grid_resolution_x * probe->grid_resolution_y * probe->grid_resolution_z; + int num_cell = probe->grid_resolution_x * probe->grid_resolution_y * probe->grid_resolution_z; + offset += num_cell; /* Update transforms */ float tmp[4][4] = { @@ -398,12 +423,26 @@ static void EEVEE_lightprobes_updates(EEVEE_SceneLayerData *sldata) sub_v3_v3(egrid->increment_z, egrid->corner); copy_v3_v3_int(egrid->resolution, &probe->grid_resolution_x); + + /* Debug Display */ + if ((probe->flag & LIGHTPROBE_FLAG_SHOW_INFLUENCE) != 0) { + struct Batch *geom = DRW_cache_sphere_get(); + DRWShadingGroup *grp = DRW_shgroup_instance_create(e_data.probe_grid_display_sh, psl->probe_display, geom); + DRW_shgroup_set_instance_count(grp, num_cell); + DRW_shgroup_uniform_int(grp, "offset", &egrid->offset, 1); + DRW_shgroup_uniform_ivec3(grp, "grid_resolution", egrid->resolution, 1); + DRW_shgroup_uniform_vec3(grp, "corner", egrid->corner, 1); + DRW_shgroup_uniform_vec3(grp, "increment_x", egrid->increment_x, 1); + DRW_shgroup_uniform_vec3(grp, "increment_y", egrid->increment_y, 1); + DRW_shgroup_uniform_vec3(grp, "increment_z", egrid->increment_z, 1); + DRW_shgroup_uniform_buffer(grp, "irradianceGrid", &sldata->irradiance_pool); + } } pinfo->num_render_grid = pinfo->num_grid; } -void EEVEE_lightprobes_cache_finish(EEVEE_SceneLayerData *sldata) +void EEVEE_lightprobes_cache_finish(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl) { EEVEE_LightProbesInfo *pinfo = sldata->probes; Object *ob; @@ -445,7 +484,7 @@ void EEVEE_lightprobes_cache_finish(EEVEE_SceneLayerData *sldata) pinfo->num_render_grid = 0; } - EEVEE_lightprobes_updates(sldata); + EEVEE_lightprobes_updates(sldata, psl); DRW_uniformbuffer_update(sldata->probe_ubo, &sldata->probes->probe_data); DRW_uniformbuffer_update(sldata->grid_ubo, &sldata->probes->grid_data); @@ -742,19 +781,17 @@ void EEVEE_lightprobes_refresh(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl } } - for (int i = 1; (ob = pinfo->probes_cube_ref[i]) && (i < MAX_PROBE); i++) { + /* Reflection probes depend on diffuse lighting thus on irradiance grid */ + for (int i = 0; (ob = pinfo->probes_grid_ref[i]) && (i < MAX_GRID); i++) { EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_get(ob); if (ped->need_update) { - LightProbe *prb = (LightProbe *)ob->data; - - render_scene_to_probe(sldata, psl, ob->obmat[3], prb->clipsta, prb->clipend); - glossy_filter_probe(sldata, psl, i); + update_irradiance_probe(sldata, psl, i); ped->need_update = false; if (!ped->ready_to_shade) { - pinfo->num_render_cube++; + pinfo->num_render_grid++; ped->ready_to_shade = true; } @@ -765,16 +802,19 @@ void EEVEE_lightprobes_refresh(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl } } - for (int i = 0; (ob = pinfo->probes_grid_ref[i]) && (i < MAX_GRID); i++) { + for (int i = 1; (ob = pinfo->probes_cube_ref[i]) && (i < MAX_PROBE); i++) { EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_get(ob); if (ped->need_update) { - update_irradiance_probe(sldata, psl, i); + LightProbe *prb = (LightProbe *)ob->data; + + render_scene_to_probe(sldata, psl, ob->obmat[3], prb->clipsta, prb->clipend); + glossy_filter_probe(sldata, psl, i); ped->need_update = false; if (!ped->ready_to_shade) { - pinfo->num_render_grid++; + pinfo->num_render_cube++; ped->ready_to_shade = true; } @@ -792,5 +832,6 @@ void EEVEE_lightprobes_free(void) DRW_SHADER_FREE_SAFE(e_data.probe_default_sh); DRW_SHADER_FREE_SAFE(e_data.probe_filter_glossy_sh); DRW_SHADER_FREE_SAFE(e_data.probe_filter_diffuse_sh); + DRW_SHADER_FREE_SAFE(e_data.probe_grid_display_sh); DRW_TEXTURE_FREE_SAFE(e_data.hammersley); } diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h index 564c9b85611..27d587bf538 100644 --- a/source/blender/draw/engines/eevee/eevee_private.h +++ b/source/blender/draw/engines/eevee/eevee_private.h @@ -54,9 +54,9 @@ typedef struct EEVEE_PassList { /* Probes */ struct DRWPass *probe_background; - struct DRWPass *probe_meshes; struct DRWPass *probe_glossy_compute; struct DRWPass *probe_diffuse_compute; + struct DRWPass *probe_display; /* Effects */ struct DRWPass *motion_blur; @@ -337,6 +337,7 @@ typedef struct EEVEE_PrivateData { struct DRWShadingGroup *shadow_shgrp; struct DRWShadingGroup *depth_shgrp; struct DRWShadingGroup *depth_shgrp_cull; + struct DRWShadingGroup *grid_display_shgrp; struct GHash *material_hash; struct GHash *hair_material_hash; } EEVEE_PrivateData; /* Transient data */ @@ -374,7 +375,7 @@ void EEVEE_lights_free(void); void EEVEE_lightprobes_init(EEVEE_SceneLayerData *sldata); void EEVEE_lightprobes_cache_init(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl); void EEVEE_lightprobes_cache_add(EEVEE_SceneLayerData *sldata, Object *ob); -void EEVEE_lightprobes_cache_finish(EEVEE_SceneLayerData *sldata); +void EEVEE_lightprobes_cache_finish(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl); void EEVEE_lightprobes_refresh(EEVEE_SceneLayerData *sldata, EEVEE_PassList *psl); void EEVEE_lightprobes_free(void); diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_frag.glsl new file mode 100644 index 00000000000..d333ad34bb0 --- /dev/null +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_frag.glsl @@ -0,0 +1,11 @@ + +flat in int cellOffset; +in vec3 worldNormal; + +out vec4 FragColor; + +void main() +{ + IrradianceData ir_data = load_irradiance_cell(cellOffset, worldNormal); + FragColor = vec4(compute_irradiance(worldNormal, ir_data), 1.0); +} diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl new file mode 100644 index 00000000000..568de294845 --- /dev/null +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl @@ -0,0 +1,34 @@ + +in vec3 pos; +in vec3 nor; + +uniform mat4 ViewProjectionMatrix; + +uniform int offset; +uniform ivec3 grid_resolution; +uniform vec3 corner; +uniform vec3 increment_x; +uniform vec3 increment_y; +uniform vec3 increment_z; + +flat out int cellOffset; +out vec3 worldNormal; + +void main() +{ + vec3 ls_cell_location; + /* Keep in sync with update_irradiance_probe */ + ls_cell_location.z = float(gl_InstanceID % grid_resolution.z); + ls_cell_location.y = float((gl_InstanceID / grid_resolution.z) % grid_resolution.y); + ls_cell_location.x = float(gl_InstanceID / (grid_resolution.z * grid_resolution.y)); + + cellOffset = offset + gl_InstanceID; + + vec3 ws_cell_location = corner + + (increment_x * ls_cell_location.x + + increment_y * ls_cell_location.y + + increment_z * ls_cell_location.z); + + gl_Position = ViewProjectionMatrix * vec4(pos * 0.02 + ws_cell_location, 1.0); + worldNormal = normalize(nor); +}
\ No newline at end of file diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c index 45f3b653b66..41541252bea 100644 --- a/source/blender/draw/intern/draw_cache.c +++ b/source/blender/draw/intern/draw_cache.c @@ -293,6 +293,12 @@ Batch *DRW_cache_fullscreen_quad_get(void) return SHC.drw_fullscreen_quad; } +/* Sphere */ +Batch *DRW_cache_sphere_get(void) +{ + return Batch_get_sphere(2); +} + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h index be05a993316..f28eca46099 100644 --- a/source/blender/draw/intern/draw_cache.h +++ b/source/blender/draw/intern/draw_cache.h @@ -33,6 +33,7 @@ void DRW_shape_cache_free(void); /* Common Shapes */ struct Batch *DRW_cache_fullscreen_quad_get(void); +struct Batch *DRW_cache_sphere_get(void); struct Batch *DRW_cache_single_vert_get(void); struct Batch *DRW_cache_single_line_get(void); struct Batch *DRW_cache_single_line_endpoints_get(void); diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index e1388346008..fecbe0f414b 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -1410,6 +1410,7 @@ static void DRW_shgroup_speaker(OBJECT_StorageList *stl, Object *ob, SceneLayer static void DRW_shgroup_lightprobe(OBJECT_StorageList *stl, Object *ob, SceneLayer *sl) { + static float one = 1.0f; float *color; LightProbe *prb = (LightProbe *)ob->data; DRW_object_wire_theme_get(ob, sl, &color); @@ -1419,7 +1420,10 @@ static void DRW_shgroup_lightprobe(OBJECT_StorageList *stl, Object *ob, SceneLay DRW_shgroup_call_dynamic_add(stl->g_data->probe, ob->obmat[3], color); if ((prb->flag & LIGHTPROBE_FLAG_SHOW_INFLUENCE) != 0) { - if (prb->attenuation_type == LIGHTPROBE_SHAPE_BOX) { + if (prb->type == LIGHTPROBE_TYPE_GRID) { + DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &one, ob->obmat); + } + else if (prb->attenuation_type == LIGHTPROBE_SHAPE_BOX) { DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &prb->distinf, ob->obmat); DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &prb->distfalloff, ob->obmat); } @@ -1432,7 +1436,6 @@ static void DRW_shgroup_lightprobe(OBJECT_StorageList *stl, Object *ob, SceneLay if ((prb->flag & LIGHTPROBE_FLAG_SHOW_PARALLAX) != 0) { float (*obmat)[4], *dist; - if ((prb->flag & LIGHTPROBE_FLAG_CUSTOM_PARALLAX) != 0) { dist = &prb->distpar; /* TODO object parallax */ |