@@ -1649,6 +1649,12 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
1649
1649
}
1650
1650
}
1651
1651
1652
+ const int max_region_size = nearest_power_of_2_templated (int (GLOBAL_GET (" rendering/lightmapping/bake_performance/region_size" )));
1653
+ const int max_rays = GLOBAL_GET (" rendering/lightmapping/bake_performance/max_rays_per_pass" );
1654
+
1655
+ const int x_regions = Math::division_round_up (atlas_size.width , max_region_size);
1656
+ const int y_regions = Math::division_round_up (atlas_size.height , max_region_size);
1657
+
1652
1658
// Set ray count to the quality used for direct light and bounces.
1653
1659
switch (p_quality) {
1654
1660
case BAKE_QUALITY_LOW: {
@@ -1718,18 +1724,53 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
1718
1724
1719
1725
RID light_uniform_set = rd->uniform_set_create (uniforms, compute_shader_primary, 1 );
1720
1726
1721
- RD::ComputeListID compute_list = rd->compute_list_begin ();
1722
- rd->compute_list_bind_compute_pipeline (compute_list, compute_shader_primary_pipeline);
1723
- rd->compute_list_bind_uniform_set (compute_list, compute_base_uniform_set, 0 );
1724
- rd->compute_list_bind_uniform_set (compute_list, light_uniform_set, 1 );
1727
+ int count = 0 ;
1728
+ for (int s = 0 ; s < atlas_slices; s++) {
1729
+ push_constant.atlas_slice = s;
1725
1730
1726
- for (int i = 0 ; i < atlas_slices; i++) {
1727
- push_constant.atlas_slice = i;
1728
- rd->compute_list_set_push_constant (compute_list, &push_constant, sizeof (PushConstant));
1729
- rd->compute_list_dispatch (compute_list, group_size.x , group_size.y , group_size.z );
1730
- // no barrier, let them run all together
1731
+ for (int i = 0 ; i < x_regions; i++) {
1732
+ for (int j = 0 ; j < y_regions; j++) {
1733
+ int x = i * max_region_size;
1734
+ int y = j * max_region_size;
1735
+ int w = MIN ((i + 1 ) * max_region_size, atlas_size.width ) - x;
1736
+ int h = MIN ((j + 1 ) * max_region_size, atlas_size.height ) - y;
1737
+
1738
+ push_constant.region_ofs [0 ] = x;
1739
+ push_constant.region_ofs [1 ] = y;
1740
+
1741
+ group_size = Vector3i (Math::division_round_up (w, 8 ), Math::division_round_up (h, 8 ), 1 );
1742
+ RD::ComputeListID compute_list = rd->compute_list_begin ();
1743
+ rd->compute_list_bind_compute_pipeline (compute_list, compute_shader_primary_pipeline);
1744
+ rd->compute_list_bind_uniform_set (compute_list, compute_base_uniform_set, 0 );
1745
+ rd->compute_list_bind_uniform_set (compute_list, light_uniform_set, 1 );
1746
+ push_constant.atlas_slice = i;
1747
+ rd->compute_list_set_push_constant (compute_list, &push_constant, sizeof (PushConstant));
1748
+ rd->compute_list_dispatch (compute_list, group_size.x , group_size.y , group_size.z );
1749
+ rd->compute_list_end ();
1750
+
1751
+ rd->submit ();
1752
+ rd->sync ();
1753
+
1754
+ count++;
1755
+ if (p_step_function) {
1756
+ int total = (atlas_slices * x_regions * y_regions);
1757
+ int percent = count * 100 / total;
1758
+ float p = float (count) / total * 0.1 ;
1759
+ if (p_step_function (0.5 + p, vformat (RTR (" Plot direct lighting %d%%" ), percent), p_bake_userdata, false )) {
1760
+ FREE_TEXTURES
1761
+ FREE_BUFFERS
1762
+ FREE_RASTER_RESOURCES
1763
+ FREE_COMPUTE_RESOURCES
1764
+ memdelete (rd);
1765
+ if (rcd != nullptr ) {
1766
+ memdelete (rcd);
1767
+ }
1768
+ return BAKE_ERROR_USER_ABORTED;
1769
+ }
1770
+ }
1771
+ }
1772
+ }
1731
1773
}
1732
- rd->compute_list_end (); // done
1733
1774
}
1734
1775
1735
1776
#ifdef DEBUG_TEXTURES
@@ -1802,17 +1843,8 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
1802
1843
RID secondary_uniform_set;
1803
1844
secondary_uniform_set = rd->uniform_set_create (uniforms, compute_shader_secondary, 1 );
1804
1845
1805
- int max_region_size = nearest_power_of_2_templated (int (GLOBAL_GET (" rendering/lightmapping/bake_performance/region_size" )));
1806
- int max_rays = GLOBAL_GET (" rendering/lightmapping/bake_performance/max_rays_per_pass" );
1807
-
1808
- int x_regions = Math::division_round_up (atlas_size.width , max_region_size);
1809
- int y_regions = Math::division_round_up (atlas_size.height , max_region_size);
1810
-
1811
1846
int ray_iterations = Math::division_round_up ((int32_t )push_constant.ray_count , max_rays);
1812
1847
1813
- rd->submit ();
1814
- rd->sync ();
1815
-
1816
1848
if (p_step_function) {
1817
1849
if (p_step_function (0.6 , RTR (" Integrate indirect lighting" ), p_bake_userdata, true )) {
1818
1850
FREE_TEXTURES
0 commit comments