Daemon icon indicating copy to clipboard operation
Daemon copied to clipboard

Possible solution to reconstruct light entities from lightmaps

Open VReaperV opened this issue 1 year ago • 1 comments

Given the conversation in #1209 I've had some thoughts on how we might be able to reconstruct light sources to create shadowmaps for maps that we don't have sources for, so I'm putting them here so they aren't lost.

One possible approach to reconstructing them would be a multi-pass process:

  1. Voxelize all of the geometry (this would probably be best done with some sort of sparse acceleration structure, since most of the map volume would be empty space). Assign values to voxels based on the lightmaps.
  2. Process groups of n×n×n voxels (there's probably a more efficient way to do this since surfaces are flat), convert RGB values into luminance, then infer light angle based on the derivative of voxels "mirrored" over the center.
  3. Convergece phase: go over each of those groups and converge angles of nearby groups. This way, if for example, there was an emissive surface that resulted in angle being deemed as 90° for some of the groups, would have it corrected. This would also mean that groups affected by more than one light source would simply converge to the nearest one. This would, however, still have edge cases, like this (light0 and light2 are at a non-90 angle, while light1 is perpendicular): image
  4. Ray tracing phase: light from each group based on those angles would be traced through the map with a specified amount of bounces, places where it hits would have some sort of value changing that represents the amount of light sources and their strength.
  5. The previously acquired values from ray tracing phase would be used to construct light sources, potentially merging multiples of them.
  6. Perhaps a phase that would recreate the lightmap and do some adjustments based on the difference between result and original lightmaps?

VReaperV avatar Sep 13 '24 16:09 VReaperV