Commit Graph

91 Commits

Author SHA1 Message Date
Ivan Avdeev e22f30608a vk: cleanup todo a bit 2024-01-18 11:33:45 -05:00
Ivan Avdeev e808fa0d9d vk: rt: enable patching environment light solid angle
Two ways:
- skybox.mat `sun_solid_angle`
- entity patch field `_xvk_solid_angle`

Both values should be specified in steradians
2024-01-18 11:14:20 -05:00
Ivan Avdeev 93cc0b5dd7 vk: rt: improve cosθ computation precision for sphere lights
It is only a bit better, makes some artifacts for strong small lights on
distant objects less visible.
2024-01-18 09:55:01 -05:00
Ivan Avdeev 7ef9bb87a9 vk: rt: fixup environment attenuation
Now environment emissive strength also depends on cos_theta (derived
from sun solid angle).
2024-01-16 13:22:32 -05:00
Ivan Avdeev e7ff1f3d3a vk: filter out degenerate triangles in brush models
This fixes lighting NaNs caused by NaN poison from invalid/zero normals.
2024-01-16 12:29:15 -05:00
Ivan Avdeev 9f1b034769 vk: rt: fix point light cos>1. for large distances 2024-01-15 12:24:24 -05:00
Ivan Avdeev 2507a629cf vk: rt: move empirical light scaling to native code
There are lots of empirical (and less-well undrestood things) scaling
color values in native code, it makes sense to consolidate them in one
place:
- less weird math in shaders. shader should be as streamlined as
  possible
- one big block of weird math is untangleable in the future when we get
  to work on light and clusters
2024-01-15 12:08:56 -05:00
Ivan Avdeev f157762043 vk: rt: pass r² to points lights from native 2024-01-15 11:40:17 -05:00
Ivan Avdeev 70b0f33f45 vk: update TODO; improve NewMap printing for debug 2024-01-15 11:28:34 -05:00
Ivan Avdeev 0fd97e2544 vk: rt: sample point light sources as spherical
1. Sample point lights as spheres. Use existing pdf value (`one_over_pdf`), as it was basically correct.
   Compute max_theta angle based on light radius and distance to the
   center. Sample cone direction based on this theta angle, in z=n space.
   Don't do anyhting fancy wrt horizon, etc.

2. Sample environment light with max theta derived from real world sun
   solid angle. Uses the same cone direction sampling.

Known issues:
- still get some NaNs sometimes, esp. on test_light map.
- Too many different light sources try to use the same code. They should
  be split.

Relevant issues: #266, #151
2024-01-12 13:31:02 -05:00
Ivan Avdeev aac4983069 vk: update todo once more 2024-01-11 12:05:42 -05:00
Ivan 'provod' Avdeev 5a89649917 vk: update TODO.md 2024-01-11 11:59:39 -05:00
Ivan 'provod' Avdeev 8f5b5657ce vk: rt: skip loading zero-area polygon lights
These cause NaNs in lighting computation, which leads to visual glitches, like strong yellow or green lighting.

Fixes #461
2024-01-11 10:35:37 -05:00
Ivan Avdeev 107c4fb048 vk: rt: add comment of what's left for math stability 2024-01-09 13:24:20 -05:00
Ivan Avdeev 8248d1d9b3 vk: rt: mask invalid H in case L ~= -V 2024-01-09 13:21:37 -05:00
Ivan Avdeev c64000195d vk: rt: organize shader printf debugging
Introduce several shader debugging/validation tiers:
1. Basic key values validation, to make sure there are no nasty NaNs or
   invalid values written to G-buffers. Enabled by `DEBUG_VALIDATE` macro
   in debug.glsl
2. Key value validation with whining: use `debugPrintfEXT()` function to
   report any invalid values to Vulkan validation layers. Enabled using
   `DEBUG_VALIDATE_PRINT` macro. Currently this is the one enabled, as
   it allows us to catch any serious numerical issues during development
   and testing.
3. Extra validation and printing for intermediate values. This is for
   deeper investigations, and enabled only there temporarily.
2024-01-09 12:05:31 -05:00
Ivan 'provod' Avdeev 64520ef5a1 vk: rt: fix magenta light glitches
It was due to some light samples having dot(N,L) < 0.
2024-01-08 13:32:49 -05:00
Ivan 'provod' Avdeev 96b4ea6345 vk: rt: use shader printf debugging to fix some nans 2024-01-08 12:03:56 -05:00
Ivan Avdeev 0bc585eddc vk: rt: split between diffuse and specular bounces
- Turn off old-vs-new brdfs comparison.
- Enable picking up specular bounces.
- Use the same final color mixing for bounces too (except for legacy
  blending, which will remain suboptimal)
2024-01-04 13:21:08 -05:00
Ivan Avdeev 54cbc85da5 vk: rt: bring bounces back with idiotic sampling
Very bad random sampling strategy, just to see some bounces.
It's super slow and noisy and isn't even unbiased or correct.
2024-01-04 11:27:02 -05:00
Ivan Avdeev e12a53fb81 vk: rt: use more correct diffuse term derivation
glTF spec one is not correct, it depends on "cached" fresnel factor, and
thus ends up including base_color twice.
2024-01-04 10:23:47 -05:00
Ivan Avdeev 3bc293d8aa vk: rt: compute legacy blending in sRGB-γ colorspace
This makes all blending look very close to the original, and fixes a
whole class of blending-looking-wrong issues.

Fixes #668
2023-12-29 12:10:54 -05:00
Ivan Avdeev 1028564eec vk: rt: enable soft alpha depth globally
Fixes #722
2023-12-28 12:09:04 -05:00
Ivan Avdeev 46e95f1255 vk: rt: linearize kusochki.color/override_color 2023-12-28 11:21:32 -05:00
Ivan Avdeev e33185c04c vk: update overall agenda a bit 2023-12-19 12:05:33 -05:00
Ivan Avdeev 239d7bc362 rt: try to clear temporal buffers on discontinuities once more
Found out that it wasn't really clearing anything.
Now it does call clear, but still there are temporal denoising
artifacts. The issue remains elusive.

Related: #661
2023-12-19 11:35:37 -05:00
Ivan Avdeev 7d7535c5c5 vk: improve logs around skybox loading 2023-12-19 10:18:57 -05:00
Ivan Avdeev d52d44e0ce vk: rt: restore skybox sampling for bounces 2023-12-19 10:06:28 -05:00
Ivan Avdeev 356f7bdf71 imagelib: load KTX2 cubemaps directly 2023-12-18 11:37:46 -05:00
Ivan Avdeev 2776373652 imagelib: do not overwrite the correct image size when building cubemap
For some very unknown reason there's a line that fixes image size to
w*h*4, which would correspond to RGBA8 pixel format w/o alignment.

This is extremely incorrect for other pixel format, e.g. compressed
ones.

Not sure why this size-fixing was there, but removing it fixes sided
KTX2 compressed skybox corruption.
2023-12-15 09:14:23 -05:00
Ivan Avdeev b1b333f74a vk: use imagelib cubemap/skybox loader
Engine imagelib already has skybox loader. It uses rgbdata_t
IMAGE_CUBEMAP flag.
1. Support IMAGE_CUBEMAP
2. Utilize imagelib skybox loader, do not try to load individual skybox
   sides manually.

This will allow loading KTX2 cubemaps directly.

Known issues:
1. Compressed KTX2 sides are not rotated correctly. Engine/imagelib is
   unable to rotate compressed images.
2. Some KTX2 sides are corrupted. Cause unknown.
2023-12-14 13:40:34 -05:00
Ivan Avdeev 6a11c6e64f vk: rt: add notes regarding engine imagelib
Also:
- add more info to texture upload debug logs
- remove obsoleted code
- prepare for engine/imagelib-side cubemaps
2023-12-14 12:41:11 -05:00
Ivan Avdeev 6fc318143e vk: rt: allow hiding all SURF_DRAWSKY surfaces while retaining skybox
Neede for getting rid of some skybox 𝘱𝘦𝘯𝘦𝘵𝘳𝘢𝘵𝘪𝘰𝘯 glitches, see #579
2023-12-14 10:54:07 -05:00
Ivan Avdeev 3cbc11a8f0 vk: rt: optimize hires skybox loading
- Do not load skybox at all if there are no SURF_DRAWSKY, #706, #579
- Do not reload the same skybox, #706

Also refactor skybox loading a bit. Prepare for KTX2 skyboxes.
2023-12-14 10:33:26 -05:00
Ivan Avdeev 5c42f34654 vk: rt: mark sky surfaces as non-geometry
SURF_SKY shouldn't receive any light, neither direct, nor indirect. Mark
it as non-geometry with ray length < 0.
2023-12-11 13:17:33 -05:00
Ivan Avdeev 6cb45dda77 vk: update notes and todo 2023-12-05 12:59:30 -05:00
Ivan Avdeev e00f758594 vk: revert back indirect specular kernel size 2023-12-05 11:14:25 -05:00
Ivan Avdeev f244aaaddf vk: update TODO 2023-12-04 13:57:06 -05:00
Ivan Avdeev 0549822d53 vk: print 'vk/module' in logs 2023-12-04 11:29:38 -05:00
Ivan Avdeev 4fd70777b7 vk: rt: increase max frame size gradually when needed 2023-12-01 10:55:58 -05:00
Ivan Avdeev 4d1b64bb19 vk: update TODO.md 2023-11-30 13:20:03 -05:00
Ivan Avdeev 32f05816e1 vk: rt: extract dynamic polylight to brush model
They don't really belong to neither rt_model_t, nor render model.
Allows having dynamic polylights for func_water entities without "main"
render model, and only water submodels.
2023-11-30 11:20:32 -05:00
Ivan Avdeev dd21e665b1 vk: patch rendermode for entities
Probably not the best way to do it, but this is an attempt.

Issue #663
2023-11-28 13:01:14 -05:00
Ivan Avdeev 735260a3c5 vk: brush: fixup per-model material mapping
fixes #669
2023-11-27 13:20:06 -05:00
Ivan Avdeev bbd96b3e0e vk: consolidate all bindings to the top of shaders
That way it is more clear what we declare, why and how.
2023-11-23 12:25:24 -05:00
Ivan Avdeev f11461772a vk: add rt_debug_fixed_random_seed cvar
Needed to pin random seed to a known value to make sure that frames are
reproducible for regression testing purposes.
2023-11-21 11:00:45 -05:00
Ivan Avdeev 4897f97726 vk: add rendertest maker script 2023-11-21 10:45:25 -05:00
Ivan Avdeev 1ac00a8792 vk: imagecompare: highlight total difference > 1% 2023-11-21 10:43:39 -05:00
Ivan Avdeev 27ed4b157a vk: rt: fixup `rt_debug_display_only lighting` 2023-11-21 10:27:58 -05:00
Ivan Avdeev 4897da4f45 vk: document frame comparison effort 2023-11-20 13:02:21 -05:00