News for hackers. Stuff that matters.
Re:Unreal 5.5 is a big deal [video] by ethagknight on Monday November 18, 2024 @01:25PM (#42175332)
Can someone ELI5 how Megalight works so much better than the prior approach, and what the tradeoffs might be? (Im not a game developer)

Reading the link below, the best I can surmise is that they shifted the prioritization from following a lightsource through all the different interactions it has, to the opposite of identifying, per pixel, how each pixel is illuminated via a prioritization scheme for light sources, including any nearby pixels. So it's a per-pixel approximation that results in a something far more accurate than the prior 'declared brute force' approach? Each pixel gets 2-5 inbound rays that have the highest impact.

How did I do?

https://dev.epicgames.com/documentation/en-us/unreal-engine/...

Re:Unreal 5.5 is a big deal [video] by wilberton on Monday November 18, 2024 @01:53PM (#42175619)
In essence mega-lights is ray tracing one shadow ray per pixel, then using some temporal de-noising to try and smooth away the noise. This is in contrast to how games traditionally calculate shadows, which is by rendering a shadow map from the point of view of each shadow casting light in the scene. For a small number of lights, the shadow map approach will be considerably faster. What mega-lights enables is effectively an unlimited number of shadow casting lights for a fixed cost (because it only ever traces a fixed number of rays per pixel), but at a much higher base performance cost, and with the potential for noisy artefacts caused by the denoising.
Re:Unreal 5.5 is a big deal [video] by WithinReason on Monday November 18, 2024 @02:31PM (#42176005)
It's actually much less accurate, but much faster.
Re:Unreal 5.5 is a big deal [video] by sigh_again on Monday November 18, 2024 @06:01PM (#42178092)
In addition, it samples a limited amount of lights at each frame (sorted by likely importance based on the position), and accumulates lighting over time: the only way you get a stable, nice image is when you leave your camera and world stable for a second. Move, and it blurs.
Re:Unreal 5.5 is a big deal [video] by jms55 on Monday November 18, 2024 @10:09PM (#42179756)
Typical rasterized pipelines with deferred rendering:

1. For each light, setup a virtual camera at the light and 1a. For each mesh, rasterize depth to a texture for that light (the shadow map) 2. For each mesh, rasterize material properties and depth to a texture for the main camera 3. For each pixel on screen 3a. For each light in the pixel's bin: sample the shadow map several times to determine if the pixel is in the light's shadow, and if not, apply the lighting for that light

By contrast, megalights:

1. For each mesh, rasterize material properties and depth to a texture for the main camera 2. For each pixel, pick a random light influenced by how close it is, how bright it is, etc 3. For each pixel, raytrace to the light. If you hit another object before the light, then you're in shadow. If not, the light is visible and affecting the point, so write the light to the direct light texture. 4. For each pixel, denoise the direct light texture by essentially blending spatially (with nearby pixels) and temporally (with pixels from the previous frame's direct light texture). 5. For each pixel, sampling the material properties and the denoised direct lighting texture, apply the lighting to the pixel and write out the final result.

The rasterized method is:

* Expensive - having to culling + rasterize every mesh per light means you can only have a few shadow casting lights * Expensive a second time - Each pixel needs to loop over all the lights in its bin * Expensive yet again - It's a lot of memory usage to store all those shadow map textures * Expensive a fourth time - To get good results, you need multiple samples of the shadow map per pixel, which is a lot of texture reads. * Poor quality - Shadow maps are a discrete approximation of shadows. Even with multiple samples, you'll often have poor quality and even artifacts unless you have either artists or a very complicated system to tweak shadow biases and cascades.

Megalights (stochastic light sampling), by contrast:

* Have a higher base overhead - ray tracing is expensive! * Scale much better - With a fixed number of rays per pixel (usually 0.5, 1, or 2), the time and memory cost at a given resolution depends mostly on the BVH complexity used for accelerating raytraces (if the random sampling is done correctly, Nvidia research shows that this can be surprisingly slow if you're not careful). Forget having only a couple shadow casting lights, now you can have thousands! * Looks much better, with much less work - No more adjusting biases or cascades or shadow sampling patterns. There's no need since raytracing is a fully continuous representation of visibiliyy between two points, unlike shadow maps. You can also integrate proper transparencies, refractions, reflections, volumetrics, emissive meshes or textures, IES light profiles, etc with raytracing, unlike rasterization. * Has different failure modes - With rasterization, too many lights or too complicated lighting will kill performance, but not quality. With megalights, performance will be fine, but you'll end up with too much noise for the denoiser to handle, which will look bad.

Re:Unreal 5.5 is a big deal [video] by zigzag312 on Tuesday November 19, 2024 @05:31AM (#42181942)
Thank you for this wonderful comparison!

With megalights, could you for each pixel, pick multiple random lights to increase accuracy?

Re:Unreal 5.5 is a big deal [video] by jms55 on Tuesday November 19, 2024 @09:13PM (#42190231)
Just realized my comment's formatting got completely messed up. I can't seem to fix it, but hope it's readable enough.

> With megalights, could you for each pixel, pick multiple random lights to increase accuracy?

You could, and megalights probably does. That's what I meant by 0.5-2 rays. Each ray you pick a different light source.

The problem is that you usually needs thousands of rays for good results in a single frame, and even a single ray more is very expensive.

Hence the reason people go as low as 0.5 per pixel (i.e. rendering at half resolution and then upscaling), and rely so much on a spatiotemporal denoiser, among other techniques.