WIP: eevee-next-world-irradiance #108304
|
@ -78,7 +78,29 @@ void Camera::sync()
|
|||
|
||||
CameraData &data = data_;
|
||||
|
||||
if (inst_.drw_view) {
|
||||
/* WORKAROUND(fclem): This is an abomination that should be remove ASAP. */
|
||||
bool is_first_baking_sync = inst_.light_probes.grids.size() == 0;
|
||||
if (inst_.is_baking() && !is_first_baking_sync) {
|
||||
/* Any view so that shadows and light culling works during irradiance bake. */
|
||||
draw::View &view = inst_.irradiance_cache.bake.view_z_;
|
||||
data.viewmat = view.viewmat();
|
||||
data.viewinv = view.viewinv();
|
||||
data.winmat = view.winmat();
|
||||
data.wininv = view.wininv();
|
||||
data.persmat = data.winmat * data.viewmat;
|
||||
data.persinv = math::invert(data.persmat);
|
||||
data.uv_scale = float2(1.0f);
|
||||
data.uv_bias = float2(0.0f);
|
||||
data.type = CAMERA_ORTHO;
|
||||
|
||||
/* \note: Follow camera parameters where distances are positive in front of the camera. */
|
||||
data.clip_near = -view.far_clip();
|
||||
data.clip_far = -view.near_clip();
|
||||
data.fisheye_fov = data.fisheye_lens = -1.0f;
|
||||
data.equirect_bias = float2(0.0f);
|
||||
data.equirect_scale = float2(0.0f);
|
||||
}
|
||||
else if (inst_.drw_view) {
|
||||
DRW_view_viewmat_get(inst_.drw_view, data.viewmat.ptr(), false);
|
||||
DRW_view_viewmat_get(inst_.drw_view, data.viewinv.ptr(), true);
|
||||
DRW_view_winmat_get(inst_.drw_view, data.winmat.ptr(), false);
|
||||
|
|
|
@ -520,6 +520,7 @@ void Instance::light_bake_irradiance(LightCache *&r_light_cache,
|
|||
};
|
||||
|
||||
/* Count probes. */
|
||||
/* TODO(fclem): Ideally, this should only iterate the despgraph and not do a full sync. */
|
||||
custom_pipeline_wrapper([&]() {
|
||||
manager->begin_sync();
|
||||
render_sync();
|
||||
|
@ -538,12 +539,16 @@ void Instance::light_bake_irradiance(LightCache *&r_light_cache,
|
|||
|
||||
for (auto i : light_probes.grids.index_range()) {
|
||||
custom_pipeline_wrapper([&]() {
|
||||
GPU_debug_capture_begin();
|
||||
irradiance_cache.bake.surfel_raster_views_sync(light_probes.grids[i]);
|
||||
/* TODO: lightprobe visibility group option. */
|
||||
manager->begin_sync();
|
||||
render_sync();
|
||||
manager->end_sync();
|
||||
|
||||
irradiance_cache.bake.surfels_create(light_probes.grids[i]);
|
||||
irradiance_cache.bake.surfels_lights_eval();
|
||||
GPU_debug_capture_end();
|
||||
});
|
||||
|
||||
int bounce_len = scene->eevee.gi_diffuse_bounces;
|
||||
|
|
|
@ -267,8 +267,6 @@ void IrradianceBake::surfels_create(const IrradianceGrid &grid)
|
|||
*/
|
||||
using namespace blender::math;
|
||||
|
||||
surfel_raster_views_sync(grid);
|
||||
|
||||
dispatch_per_grid_sample_ = math::divide_ceil(grid.resolution, int3(IRRADIANCE_GRID_GROUP_SIZE));
|
||||
capture_info_buf_.irradiance_grid_size = grid.resolution;
|
||||
capture_info_buf_.irradiance_grid_local_to_world = grid.transform;
|
||||
|
@ -350,6 +348,9 @@ void IrradianceBake::surfels_create(const IrradianceGrid &grid)
|
|||
empty_raster_fb_.ensure(transform_point(invert(basis_z_), grid_pixel_extent_).xy());
|
||||
inst_.pipelines.capture.render(view_z_);
|
||||
|
||||
/* Sync with any other following pass using the surfel buffer. */
|
||||
GPU_memory_barrier(GPU_BARRIER_SHADER_STORAGE);
|
||||
|
||||
DRW_stats_group_end();
|
||||
}
|
||||
|
||||
|
@ -363,7 +364,7 @@ void IrradianceBake::surfels_lights_eval()
|
|||
inst_.shadows.set_view(view_z_);
|
||||
inst_.render_buffers.release();
|
||||
|
||||
inst_.manager->submit(surfel_light_eval_ps_);
|
||||
inst_.manager->submit(surfel_light_eval_ps_, view_z_);
|
||||
}
|
||||
|
||||
void IrradianceBake::propagate_light_sample()
|
||||
|
|
|
@ -17,18 +17,24 @@ namespace blender::eevee {
|
|||
|
||||
class Instance;
|
||||
class CapturePipeline;
|
||||
class ShadowModule;
|
||||
class Camera;
|
||||
|
||||
/**
|
||||
* Baking related pass and data. Not used at runtime.
|
||||
*/
|
||||
class IrradianceBake {
|
||||
friend CapturePipeline;
|
||||
friend ShadowModule;
|
||||
friend Camera;
|
||||
|
||||
private:
|
||||
Instance &inst_;
|
||||
|
||||
/** Light cache being baked. */
|
||||
LightCache *light_cache_ = nullptr;
|
||||
/** Surface elements that represent the scene. */
|
||||
SurfelBuf surfels_buf_;
|
||||
/** Capture state. */
|
||||
CaptureInfoBuf capture_info_buf_;
|
||||
/** Framebuffer. */
|
||||
|
@ -81,13 +87,10 @@ class IrradianceBake {
|
|||
float3 grid_location_;
|
||||
/* Bounding box vertices of the irradiance grid being baked. In world space. */
|
||||
Vector<float3> grid_bbox_vertices;
|
||||
|
||||
public:
|
||||
/** Surface elements that represent the scene. */
|
||||
SurfelBuf surfels_buf_;
|
||||
/* Surfel per unit distance. */
|
||||
float surfel_density_ = 2.0f;
|
||||
|
||||
public:
|
||||
IrradianceBake(Instance &inst) : inst_(inst){};
|
||||
|
||||
void sync();
|
||||
|
|
|
@ -708,6 +708,7 @@ void ShadowModule::begin_sync()
|
|||
|
||||
if (inst_.is_baking()) {
|
||||
SurfelBuf &surfels_buf = inst_.irradiance_cache.bake.surfels_buf_;
|
||||
CaptureInfoBuf &capture_info_buf = inst_.irradiance_cache.bake.capture_info_buf_;
|
||||
float surfel_coverage_area = inst_.irradiance_cache.bake.surfel_density_;
|
||||
|
||||
/* Directional shadows. */
|
||||
|
@ -720,13 +721,15 @@ void ShadowModule::begin_sync()
|
|||
sub.shader_set(inst_.shaders.static_shader_get(SHADOW_TILEMAP_TAG_USAGE_SURFELS));
|
||||
sub.bind_ssbo("tilemaps_buf", &tilemap_pool.tilemaps_data);
|
||||
sub.bind_ssbo("tiles_buf", &tilemap_pool.tiles_data);
|
||||
sub.bind_ssbo("surfels_buf", &surfels_buf);
|
||||
sub.bind_ssbo("surfel_buf", &surfels_buf);
|
||||
sub.bind_ssbo("capture_info_buf", &capture_info_buf);
|
||||
sub.push_constant("directional_level", directional_level);
|
||||
sub.push_constant("tilemap_projection_ratio", projection_ratio);
|
||||
inst_.lights.bind_resources(&sub);
|
||||
sub.dispatch(int3(surfels_buf.size(), 1, 1));
|
||||
sub.dispatch(&inst_.irradiance_cache.bake.dispatch_per_surfel_);
|
||||
|
||||
return; /* Skip opaque and transparent tagging for light baking. */
|
||||
/* Skip opaque and transparent tagging for light baking. */
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
|
|
|
@ -198,7 +198,8 @@ void shadow_tag_usage_surfel(Surfel surfel, int directional_level)
|
|||
|
||||
LIGHT_FOREACH_BEGIN_LOCAL_NO_CULL(light_cull_buf, l_idx)
|
||||
{
|
||||
float dist_to_cam = 1; /* Set it to 1 to avoid changing footprint_ratio. */
|
||||
/* Set distance to camera to 1 to avoid changing footprint_ratio. */
|
||||
float dist_to_cam = 1.0;
|
||||
shadow_tag_usage_tilemap_punctual(l_idx, P, dist_to_cam, 0);
|
||||
}
|
||||
LIGHT_FOREACH_END
|
||||
|
|
|
@ -11,6 +11,11 @@
|
|||
|
||||
void main()
|
||||
{
|
||||
Surfel surfel = surfels_buf[gl_GlobalInvocationID.x];
|
||||
int index = int(gl_GlobalInvocationID.x);
|
||||
if (index >= capture_info_buf.surfel_len) {
|
||||
return;
|
||||
}
|
||||
|
||||
Surfel surfel = surfel_buf[index];
|
||||
shadow_tag_usage_surfel(surfel, directional_level);
|
||||
}
|
||||
|
|
|
@ -62,13 +62,16 @@ GPU_SHADER_CREATE_INFO(eevee_shadow_tag_usage_opaque)
|
|||
|
||||
GPU_SHADER_CREATE_INFO(eevee_shadow_tag_usage_surfels)
|
||||
.do_static_compilation(true)
|
||||
.local_group_size(1, 1, 1)
|
||||
.storage_buf(5, Qualifier::READ_WRITE, "ShadowTileMapData", "tilemaps_buf[]")
|
||||
.storage_buf(6, Qualifier::READ_WRITE, "ShadowTileDataPacked", "tiles_buf[]")
|
||||
.storage_buf(7, Qualifier::READ_WRITE, "Surfel", "surfels_buf[]")
|
||||
.local_group_size(SURFEL_GROUP_SIZE)
|
||||
.storage_buf(6, Qualifier::READ_WRITE, "ShadowTileMapData", "tilemaps_buf[]")
|
||||
.storage_buf(7, Qualifier::READ_WRITE, "ShadowTileDataPacked", "tiles_buf[]")
|
||||
.push_constant(Type::INT, "directional_level")
|
||||
.push_constant(Type::FLOAT, "tilemap_projection_ratio")
|
||||
.additional_info("eevee_shared", "draw_view", "draw_view_culling", "eevee_light_data")
|
||||
.additional_info("eevee_shared",
|
||||
"draw_view",
|
||||
"draw_view_culling",
|
||||
"eevee_light_data",
|
||||
"eevee_surfel_common")
|
||||
.compute_source("eevee_shadow_tag_usage_surfels_comp.glsl");
|
||||
|
||||
GPU_SHADER_INTERFACE_INFO(eevee_shadow_tag_transparent_iface, "interp")
|
||||
|
|
Loading…
Reference in New Issue