Try / OpenGothic

Reimplementation of Gothic 2 Notr
MIT License
1.14k stars 80 forks source link

RT: Global illumination #510

Open Try opened 1 year ago

Try commented 1 year ago

Concept

First prototype (branch: https://github.com/Try/OpenGothic/tree/gi-rendering)

изображение

and probes(~30k): изображение

Reference materials:

Lumen: https://advances.realtimerendering.com/s2022/SIGGRAPH2022-Advances-Lumen-Wright%20et%20al.pdf изображение

Combination of screen-space probes and world-space cache, for HW-RT part. In paper there is a lot about SDF and software ray-tracing, yet we wont do it, as so requires precomputational part in asset-pipeline

EA-surfels: https://www.youtube.com/watch?v=h1ocYFrtsM4 изображение

PRT probes: http://mrakobes.com/Nikolay.Stefanov.GDC.2016.pdf изображение

Personally prefer this workflow (except we will have to do ray-casting in runtime)

Good summary on light-leaks : https://handmade.network/p/75/monter/blog/p/7288-engine_work__global_illumination_with_irradiance_probes

Nice open-source project with multiple techniques implemented: https://github.com/EmbarkStudios/kajiya/blob/main/docs/gi-overview.md

Try commented 1 year ago

Added probe-caching; continue cleaning-up lightingcode: изображение

~3k probes are recalculated each frame ~27k in total No SSAO/Bent-normal integration (yet?)

Need to refine caching scheme: cache ray-hit instead of irradicance

Try commented 1 year ago

Some more screenshoots: изображение изображение изображение

Try commented 1 year ago

Rework for probe-grid lod: изображение

Now probes do have almost consistent distribution in screen-space with similar budget

Try commented 1 year ago

Still working on secondary bounces. More screenshots: изображение изображение изображение изображение

Try commented 1 year ago

black-and-white version изображение

clort81 commented 10 months ago

Wanted to play with RT for ages and never found a FOSS implementation i liked. Following your work here, and very thankful to read your notes and results.

Try commented 8 months ago

Metal backend also works now: изображение

Not much FPS on M1, yet still happy that Metal-backed now has less bugs :)

Try commented 6 months ago

Updated albedo-fetch heuristics: изображение

Notes: albedo-fetch is a horrible hack that enables usage photo-texture of vanilla game, and attempts to extract usable color information

Try commented 6 months ago

Working on narrowing down, what is not working. When similar view-angle rendered with albedo=0.9 image look correct: изображение

Try commented 6 months ago

Still tuning textures/color-bleeding. GI: изображение No-GI: изображение

Try commented 6 months ago

Going thru https://physicallybased.info

Sun (above atmosphere): 143'000.f -> 128'000.f Sun (on land): engine results in ~100.000f, matches real world observation Sky (median) was ~3% of sun-light (too low), after changing ground albedo factor (0.1 -> 0.3), becomes ~4.7% (correct)

Uniform-ambient is estimated as: ~sun * transmissioni * ang * p * 0.5 * 2pi~ - bunch of hacks; TODO.

After many adjustment: изображение

toolatetotheparty commented 6 months ago

The latest screenshot looks more and less physically correct at the same time. The intensity of direct sunlight looks less clipped, but the GI deep inside the building looks gone, allowing that ghastly blueish fake GI they did to show through. 🤔

upd. Though, on a second thought, there wouldn't be enough energy for indirect sunlight to bounce so many times and color everything orange... Anyways, some AO feeding on your GI implementation is also needed. Removing the effects of these blue-tinted light probes would do wonders for the general aesthetics.

Try commented 6 months ago

Main issue with GI (or lighting in general), when it comes to gothic, are materials. Or should I say - lack there of.

GI (and diffuse lighting) needs albedo data, but only thing we have in assets is a "photo-texture". For the sake of rendering I have heuristics here:

This is path one. Part 2: this heuristic has to be symmetrical with engine lighting.

Part 3. Due to the way inverse-tonemapping works, acesTonemapInv(1.0/*white*/) = inf

Try commented 6 months ago

Anyways, some AO feeding on your GI implementation is also needed

I do simply multiply GI by AO (what is not correct, but give at least some detail). Here is AO изображение

Probably it would be better to use output bent-normal, from AO pass and use it intead

Try commented 6 months ago

Is it possible to further adjust AO so that it would work not only by seeking intersecting geometry but also volumetrically, with respect to how your GI works by gradually shading the whole interior?

Sorry, I don't know what do you mean. If AO is by definition ratio of ray-hit/ray-miss, and if shader checking not only intersection - than it's not AO

Try commented 6 months ago

gradually shading the whole interior?

Scene above is not interior: изображение

When it comes to castle wall, it expected to be split 50:50, between ray-misses (samples sky-color) and hit on street floor. Street-floor has no direct component (it's in shadow), and indirect is also sky*albedo

Try commented 6 months ago

2k shadowmap unfortunately not good enough to take care of shadow-term. Also secondary-bounces are disabled, as I'm debugging atm. изображение изображение

almost like lumen: изображение

Try commented 5 months ago

Debug view of ray-hits (needed to evaluate solution for secondary bounces): изображение

изображение

Try commented 4 months ago

Been evaluating different approaches for iradiance cache and secondary bounces. Unlike Lumen, in OpenGothic we cannot do offline baking, and have to have runtime solution for gi-scene. Here example of hash-map of primitives that been touched by rays: изображение изображение

Every colored triangle is a single cache-entry and small primitives are also tessellated by bird-curve, to improve resolution a bit. Still not OK unfortunately: too much memory (~200+MB) and too low res