Skip to content

Commit fc9c75f

Browse files
committed
LightmapGI: Pack L1 SH coefficients before denoising
1 parent 7cc3f37 commit fc9c75f

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

modules/lightmapper_rd/lightmapper_rd.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,6 +2065,14 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
20652065

20662066
/* DENOISE */
20672067

2068+
if (p_bake_sh) {
2069+
SWAP(light_accum_tex, light_accum_tex2);
2070+
BakeError error = _pack_l1(rd, compute_shader, compute_base_uniform_set, push_constant, light_accum_tex2, light_accum_tex, atlas_size, atlas_slices);
2071+
if (unlikely(error != BAKE_OK)) {
2072+
return error;
2073+
}
2074+
}
2075+
20682076
if (p_use_denoiser) {
20692077
if (p_step_function) {
20702078
if (p_step_function(0.8, RTR("Denoising"), p_bake_userdata, true)) {
@@ -2290,14 +2298,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d
22902298
}
22912299
}
22922300

2293-
if (p_bake_sh) {
2294-
SWAP(light_accum_tex, light_accum_tex2);
2295-
BakeError error = _pack_l1(rd, compute_shader, compute_base_uniform_set, push_constant, light_accum_tex2, light_accum_tex, atlas_size, atlas_slices);
2296-
if (unlikely(error != BAKE_OK)) {
2297-
return error;
2298-
}
2299-
}
2300-
23012301
#ifdef DEBUG_TEXTURES
23022302

23032303
for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) {

modules/lightmapper_rd/lm_compute.glsl

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,24 +1280,13 @@ void main() {
12801280

12811281
#ifdef MODE_PACK_L1_COEFFS
12821282
vec4 base_coeff = texelFetch(sampler2DArray(source_light, linear_sampler), ivec3(atlas_pos, params.atlas_slice * 4), 0);
1283+
imageStore(dest_light, ivec3(atlas_pos, params.atlas_slice * 4), base_coeff);
12831284

12841285
for (int i = 1; i < 4; i++) {
12851286
vec4 c = texelFetch(sampler2DArray(source_light, linear_sampler), ivec3(atlas_pos, params.atlas_slice * 4 + i), 0);
1287+
c.rgb /= (base_coeff.rgb * 8.0 + vec3(1e-6f));
1288+
c.rgb = clamp(c.rgb + vec3(0.5), vec3(0.0), vec3(1.0));
12861289

1287-
if (abs(base_coeff.r) > 0.0) {
1288-
c.r /= (base_coeff.r * 8);
1289-
}
1290-
1291-
if (abs(base_coeff.g) > 0.0) {
1292-
c.g /= (base_coeff.g * 8);
1293-
}
1294-
1295-
if (abs(base_coeff.b) > 0.0) {
1296-
c.b /= (base_coeff.b * 8);
1297-
}
1298-
1299-
c.rgb += vec3(0.5);
1300-
c.rgb = clamp(c.rgb, vec3(0.0), vec3(1.0));
13011290
imageStore(dest_light, ivec3(atlas_pos, params.atlas_slice * 4 + i), c);
13021291
}
13031292
#endif

0 commit comments

Comments
 (0)