WIP: eevee-next-world-irradiance #108304

Closed
Jeroen Bakker wants to merge 79 commits from Jeroen-Bakker:eevee-next-world-irradiance into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
10 changed files with 127 additions and 3 deletions
Showing only changes of commit a484f43a17 - Show all commits

View File

@ -598,6 +598,7 @@ class RENDER_PT_eevee_next_indirect_lighting(RenderButtonsPanel, Panel):
col.prop(props, "gi_auto_bake")
col.prop(props, "gi_diffuse_bounces")
col.prop(props, "gi_irradiance_samples")
col.prop(props, "gi_show_irradiance")
class RENDER_PT_eevee_indirect_lighting_display(RenderButtonsPanel, Panel):

View File

@ -446,6 +446,8 @@ set(GLSL_SRC
engines/eevee_next/shaders/eevee_depth_of_field_stabilize_comp.glsl
engines/eevee_next/shaders/eevee_depth_of_field_tiles_dilate_comp.glsl
engines/eevee_next/shaders/eevee_depth_of_field_tiles_flatten_comp.glsl
engines/eevee_next/shaders/eevee_display_probe_grid_frag.glsl
engines/eevee_next/shaders/eevee_display_probe_grid_vert.glsl
engines/eevee_next/shaders/eevee_film_comp.glsl
engines/eevee_next/shaders/eevee_film_cryptomatte_post_comp.glsl
engines/eevee_next/shaders/eevee_film_frag.glsl

View File

@ -25,12 +25,21 @@ void IrradianceCache::sync()
{
if (!inst_.is_baking()) {
debug_pass_sync();
display_pass_sync();
}
else {
bake.sync();
}
}
void IrradianceCache::viewport_draw(View &view, GPUFrameBuffer *view_fb)
{
if (!inst_.is_baking()) {
debug_pass_draw(view, view_fb);
display_pass_draw(view, view_fb);
}
}
void IrradianceCache::debug_pass_sync()
{
if (!ELEM(inst_.debug_mode,
@ -67,7 +76,7 @@ void IrradianceCache::debug_pass_sync()
debug_surfels_ps_.draw_procedural(GPU_PRIM_TRI_STRIP, surfels_buf_.size(), 4);
}
void IrradianceCache::debug_draw(View &view, GPUFrameBuffer *view_fb)
void IrradianceCache::debug_pass_draw(View &view, GPUFrameBuffer *view_fb)
{
switch (inst_.debug_mode) {
case eDebugMode::DEBUG_IRRADIANCE_CACHE_SURFELS_NORMAL:
@ -85,6 +94,42 @@ void IrradianceCache::debug_draw(View &view, GPUFrameBuffer *view_fb)
inst_.manager->submit(debug_surfels_ps_, view);
}
void IrradianceCache::display_pass_sync()
{
LightCache *light_cache = inst_.scene->eevee.light_cache_data;
display_grids_enabled_ = light_cache && light_cache->grid_len > 0 && light_cache->grids &&
DRW_state_draw_support() &&
inst_.scene->eevee.flag & SCE_EEVEE_SHOW_IRRADIANCE;
if (!display_grids_enabled_) {
return;
}
display_grids_ps_.init();
display_grids_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_CULL_BACK);
display_grids_ps_.shader_set(inst_.shaders.static_shader_get(DISPLAY_PROBE_GRID));
for (auto i : IndexRange(light_cache->grid_len)) {
LightCacheIrradianceGrid &grid = light_cache->grids[i];
display_grids_ps_.push_constant("sphere_radius", 0.1f);
display_grids_ps_.push_constant("grid_resolution", int3(grid.resolution));
float4x4 grid_to_world = math::invert(float4x4(grid.world_to_grid));
display_grids_ps_.push_constant("grid_to_world", grid_to_world);
int cell_count = grid.resolution[0] * grid.resolution[1] * grid.resolution[2];
display_grids_ps_.draw_procedural(GPU_PRIM_TRIS, 1, cell_count * 3 * 2);
}
}
void IrradianceCache::display_pass_draw(View &view, GPUFrameBuffer *view_fb)
{
if (display_grids_enabled_) {
GPU_framebuffer_bind(view_fb);
inst_.manager->submit(display_grids_ps_, view);
}
}
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -109,15 +109,22 @@ class IrradianceCache {
/** Debug surfel elements copied from the light cache. */
draw::StorageVectorBuffer<Surfel> surfels_buf_;
bool display_grids_enabled_ = false;
PassSimple display_grids_ps_ = {"IrradianceCache.Display Grids"};
public:
IrradianceCache(Instance &inst) : bake(inst), inst_(inst){};
~IrradianceCache(){};
void init();
void sync();
void viewport_draw(View &view, GPUFrameBuffer *view_fb);
private:
void debug_pass_sync();
void debug_draw(View &view, GPUFrameBuffer *view_fb);
void debug_pass_draw(View &view, GPUFrameBuffer *view_fb);
void display_pass_sync();
void display_pass_draw(View &view, GPUFrameBuffer *view_fb);
};
} // namespace blender::eevee

View File

@ -102,6 +102,8 @@ const char *ShaderModule::static_shader_create_info_name_get(eShaderType shader_
return "eevee_motion_blur_tiles_flatten_viewport";
case DEBUG_SURFELS:
return "eevee_debug_surfels";
case DISPLAY_PROBE_GRID:
return "eevee_display_probe_grid";
case DOF_BOKEH_LUT:
return "eevee_depth_of_field_bokeh_lut";
case DOF_DOWNSAMPLE:

View File

@ -34,6 +34,8 @@ enum eShaderType {
DEBUG_SURFELS,
DISPLAY_PROBE_GRID,
DOF_BOKEH_LUT,
DOF_DOWNSAMPLE,
DOF_FILTER,

View File

@ -134,7 +134,7 @@ void ShadingView::render()
inst_.lights.debug_draw(render_view_new_, combined_fb_);
inst_.hiz_buffer.debug_draw(render_view_new_, combined_fb_);
inst_.shadows.debug_draw(render_view_new_, combined_fb_);
inst_.irradiance_cache.debug_draw(render_view_new_, combined_fb_);
inst_.irradiance_cache.viewport_draw(render_view_new_, combined_fb_);
GPUTexture *combined_final_tx = render_postfx(rbufs.combined_tx);

View File

@ -0,0 +1,16 @@
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
void main()
{
float dist_sqr = dot(lP, lP);
/* Discard outside the circle. */
if (dist_sqr > 1.0) {
discard;
return;
}
vec3 vN = vec3(lP, sqrt(max(0.0, 1.0 - dist_sqr)));
vec3 P = mat3(ViewMatrixInverse) * vN;
out_color = vec4(normal_view_to_world(vN) * 0.5 + 0.5, 1.0);
}

View File

@ -0,0 +1,34 @@
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
void main()
{
/* Constant array moved inside function scope.
* Minimises local register allocation in MSL. */
const vec2 pos[6] = vec2[6](vec2(-1.0, -1.0),
vec2(1.0, -1.0),
vec2(-1.0, 1.0),
vec2(1.0, -1.0),
vec2(1.0, 1.0),
vec2(-1.0, 1.0));
lP = pos[gl_VertexID % 6];
cell_index = gl_VertexID / 6;
/* Keep in sync with update_irradiance_probe. */
ivec3 cell = ivec3(cell_index / (grid_resolution.z * grid_resolution.y),
(cell_index / grid_resolution.z) % grid_resolution.y,
cell_index % grid_resolution.z);
vec3 ls_cell_pos = (vec3(cell) + vec3(0.5)) / vec3(grid_resolution);
ls_cell_pos = ls_cell_pos * 2.0 - 1.0; /* Remap to (-1 ... +1). */
vec3 ws_cell_pos = (grid_to_world * vec4(ls_cell_pos, 1.0)).xyz;
vec3 vs_offset = vec3(lP, 0.0) * sphere_radius;
vec3 vP = (ViewMatrix * vec4(ws_cell_pos, 1.0)).xyz + vs_offset;
gl_Position = ProjectionMatrix * vec4(vP, 1.0);
gl_Position.z += 0.0001; /* Small bias to let the icon draw without zfighting. */
}

View File

@ -60,3 +60,18 @@ GPU_SHADER_CREATE_INFO(eevee_surfel_ray)
.additional_info("eevee_shared", "eevee_surfel_common", "draw_view")
.compute_source("eevee_surfel_ray_comp.glsl")
.do_static_compilation(true);
GPU_SHADER_INTERFACE_INFO(eevee_display_probe_grid_iface, "")
.smooth(Type::VEC2, "lP")
.flat(Type::INT, "cell_index");
GPU_SHADER_CREATE_INFO(eevee_display_probe_grid)
.additional_info("eevee_shared", "draw_view")
.vertex_source("eevee_display_probe_grid_vert.glsl")
.vertex_out(eevee_display_probe_grid_iface)
.fragment_source("eevee_display_probe_grid_frag.glsl")
.fragment_out(0, Type::VEC4, "out_color")
.push_constant(Type::FLOAT, "sphere_radius")
.push_constant(Type::IVEC3, "grid_resolution")
.push_constant(Type::MAT4, "grid_to_world")
.do_static_compilation(true);