Commit Graph

720 Commits

Author SHA1 Message Date
Ivan Avdeev 0e403e119f vk: silence degenerate triangle diagnostic logs 2024-01-18 11:13:16 -05:00
Ivan Avdeev de60cde7ab vk: rt: suggest dithering for precision errors 2024-01-18 09:59:02 -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 2cc2ca3965 vk: rt: add extra debug printfs around oob light clusters 2024-01-15 12:11:52 -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 'provod' Avdeev dc6cca0d7f vk: rt: skip stale light clusters point light indexes
See #730
2024-01-15 11:26:31 -05:00
Ivan Avdeev 065bab855a vk: rt: fixup debug validaion modes in shaders 2024-01-12 13:48:53 -05:00
Ivan Avdeev e398fe5ef3 vk: rt: diagnose remaining point/sphere light NaNs
They're due to `P` being NaN already, which is fed from outside.
2024-01-12 13:39:36 -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 3153a83621 vk: rt: add material debug display mode
Also add debug display modes info
2024-01-11 11:56:23 -05:00
Ivan 'provod' Avdeev 02afc7b320 vk: rt: invert pdf for point lights
This makes math even more stable, but it removes imprecisions that were accidentally helping the rendered image. Thus it looks a bit darker.
Fixing that would need proper sampling, with disc angle and what not.
2024-01-11 11:36:35 -05:00
Ivan 'provod' Avdeev dd17dee35d vk: rt: improve point light computation stability
Guard against:
- spot_attenuation being too small
- pdf denom being zero. It could be inverted, e.g. not pdf=1/denom, but one_over_pdf = denom and then multiplying color with that directly, but we'd still need to clamp it to positive values.
2024-01-11 11:20:45 -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 2961ad5b1a vk: rt: use simple hemisphere cosine sampling for diffuse bounces
As opposed to more compute intensive local-frame sampling. They seem to
produce the same results.

Local-frame sampling might still be needed for specular bounces.
2024-01-09 12:09:41 -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 Avdeev a147c89a53 vk: rt: fixup reprojection black borders 2024-01-08 13:55:39 -05:00
Ivan 'provod' Avdeev 20e9af6496 vk: rt: allow disabling debug printfs in shaders 2024-01-08 13:45:00 -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 dee067c771 vk: remove unused code 2024-01-08 13:29:52 -05:00
Ivan 'provod' Avdeev 62fd27ad65 vk: mark all shader printfs as S_ERROR 2024-01-08 13:29:30 -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 'provod' Avdeev a5086486fa vk: silence too eager stage mask sync validation complaint 2024-01-08 11:55:14 -05:00
Ivan Avdeev 5906f72e0d vk: rt: pick bounce direction by cosine-hemisphere sampling
Also:
- move sampling to brdf.glsl
- do only 1 bounce w/o comparison (for testing)
- do only diffuse (for testing)
2024-01-05 20:06:01 -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 55fe48659e [wip] vk: rt: add 2nd bounces w/ idiotic sampling
Completely rework bounces, allow 2nd+ bounces.

Still work in progress with lots of debug code.
2024-01-04 13:10:26 -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 6a04888a3c vk: rt: fix artifacts due to missing dot(N,L) term
We missed it because BRDF model of glTF 2.0 expects this term to be in
the rendering equation integral, and not in the BRDF function itself.

Boksajak's `brdf.h` model does include this term in the BRDF because the
cancel out for some usages beautifully.

Also, add comparison macro so we can see old-vs-new PBR model.
2024-01-04 09:56:04 -05:00
Ivan Avdeev e9b05ff849 vk: rt: add direct_{diff,spec} debug display
also try to simplify brdf ggx math
2024-01-02 13:32:49 -05:00
Ivan Avdeev 5544b99db9 vk: rt: do not forget to add new files you dumbass 2024-01-02 13:12:40 -05:00
Ivan Avdeev 88b24ad3bd vk: rt: rewrite direct-eval brdfs from scratch
Deprecate `brdf.h` usage, start writing our own BRDF functions.

Use glTF 2.0 BRDF mixing model as a simple starting point.
Mix-in base_color into specular early, as it is light-direction
dependent and cannot be easily separated.

Disable bounces for now, as we don't have yet good sampling story, need
to write "backwards" BRDFs that give us ray directions to sample, and
accommodate for that sampling bias in BRDF attenuation itself.

Also introduces some other weird artifacts on `test_material` map, investigation pending.

Related to black metals in #666
2024-01-02 13:01:58 -05:00
Ivan Avdeev 9088ab3dc4 vk: rt: fixup accidental translucency for alpha-masked geometries
Fixes #721
2024-01-01 11:07:53 -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 310ecff585 vk: rt: make additive brush models single-sided
Fixes #665
2023-12-22 15:19:24 -05:00
Ivan Avdeev 180f3ed9cb vk: rt: allow per-model back face culling
Make transparent studio models, e.g. holograms, single-sided.

Related: #665
2023-12-22 15:14:27 -05:00
Ivan Avdeev caac371681 vk: rt: tune emissive/additive blending so that it matches original
To match original more closely it additive geometry should be added to
final color in sRGB-γ space. You might not like that it is physically
incorrect, but this is what peak compatibility looks like.

Related to #668
2023-12-22 14:23:22 -05:00
Ivan Avdeev 59f7d264c2
Merge pull request #716 from 0x4E69676874466F78/rad&patches
Add new rad files
add c2a5a.rad c2a5d.rad c2a5e.rad
2023-12-21 06:35:33 -08:00
Aty_0 c60d851ad8 Fix traditional render tries to load bluenoise 2023-12-20 23:43:12 +03:00
NightFox 0a6b40e0ab
Add new rad files 2023-12-20 18:15:54 +03:00
Ivan Avdeev 4b605810f3
Merge pull request #713 from 0x4E69676874466F78/rad&patches
Update patches

Fix texture coordinates for monitors (c1a0, c1a1f)
2023-12-20 06:41:54 -08: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
NightFox fc1a553bc7
Fix texture coordinates for monitors (c1a0, c1a1f) 2023-12-19 01:48:02 +03:00
Ivan Avdeev a0b36a4301 vk: trad: allow rendering with replaced PBR textures
Use `vk_use_material_textures` cvar to show new PBR material textures
for traditional rendering.
Note that they're often sampled in an incorrect colorspace, so they look
different from RT.

Fixes #711
2023-12-18 09:57:01 -08:00
Ivan Avdeev 7e0553d408
Merge pull request #708 from w23/stream-E346
Skybox improvements (E346-E349)

- [x] #706 
  - [x] Do not load skybox if map doesn't have any `SURF_DRAWSKY` surfaces.
  - [x] Cache: do not reload the same skybox.
  - [x] Enable loading packed KTX2 cubemaps as skyboxes in engine/imagelib
- [x] Reuse existing imagelib cubemap loading routines, remove custom skybox loading code
- [x] Allow hiding `SURF_DRAWSKY` surfaces via `"_xvk_remove_all_sky_surfaces" "1"`, #579 
- [x] #677 
  - [x] Add skybox exposure control for HDR skyboxes
  - [x] Allow reloading skyboxes when reloading patches
2023-12-18 09:56:04 -08:00
Ivan Avdeev bec1e0f558 vk: rt: add tunable skybox exposure
E.g. add `desert.mat` alongside `desert.ktx2` (or
`desrt_{rt,lf,...}.png` files) with the following contents:
```
exposure 0.3
```
Skybox texture color will be multiplied by this value.
2023-12-18 12:26:01 -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
nilsoncore a06998321e vk: devmem: track peak single allocation size 2023-12-14 08:13:26 +03:00
nilsoncore cba1b02103 vk: devmem: print human-friendly memory size values
Raw values are still printed in subsequent messages.
2023-12-14 08:00:21 +03:00
nilsoncore ceb4437f8c vk: devmem: print number of alloc slots on overflow 2023-12-14 07:54:23 +03:00
nilsoncore 05ac770c81 vk: devmem: track alignment holes correctly
Get `alignment_hole` right from the `alolcator` instead of calculating
outside.
Improve allocation slot variable naming on slot allocation selection.
Restructure internal `vk_devmem_t` fields into `internal` struct.
Make `VK_DevMemUsageTypeString` visibility scope to file-only.
2023-12-14 07:50:15 +03:00
nilsoncore 1117c5969e vk: devmem: simplify flags formatting
Use `PRI_VKxxxFLAGS_FMT` as an inline format macro and
`PRI_VKxxxFLAGS_ARG( ... )` as an inline argument macro for that format.
Also bring back those `!!`.
2023-12-14 07:39:44 +03:00
Ivan Avdeev 9a0ff43a97
Merge pull request #707 from 0x4E69676874466F78/no_ray_warn
Improved warning when there are no ray extensions

fix #670
2023-12-12 14:42:44 -08:00
NightFox 726572b78c
minor reorganization 2023-12-13 01:13:48 +03:00
NightFox 0d3c9ba88d
Warning after getting a candidate 2023-12-12 19:46:04 +03:00
NightFox 852b7c28ba
Slight improvement of code 2023-12-12 14:56:35 +03:00
NightFox 1a9f97bb14
Added warnings about 32bit when configure 2023-12-12 14:31:20 +03:00
NightFox e1868c752f
Improved warning when there are no ray extensions
fix #670
2023-12-12 13:55:12 +03: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 4ac62076bb vk: use original texture for sprites in rasterization mode
Traditional rasterization should not use any of the patched textures.

Fixes #695
2023-12-11 12:55:32 -05:00
Ivan Avdeev c8123952a2 vk: rt: fix incorrect basecolor brdf multiplication
PBR model used implies the following rules:
- for metals both diffuse and specular components should be tinted by
  material base color.
- for dielectrics, only diffuse should be tinted, specular should remain
  as is.

Partially fixes #666
2023-12-11 11:48:44 -05:00
NightFox e89e44d94a
Add & update rad files
c2a4d.rad, c2a4e.rad, c2a4f.rad
2023-12-08 18:35:44 +03:00
NightFox b22d87ae82
Update c2a4a.rad
add missing +A~FIFTIES_LGT2
2023-12-07 18:54:40 +03:00
NightFox 20cbe33f2f
add c2a3e.patch 2023-12-07 17:12:21 +03:00
NightFox 1bec8ad9b9
Add new rad files 2023-12-07 17:11:55 +03: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
NightFox 58572380ab
Update rad files 2023-12-05 17:11:26 +03:00
NightFox de3f350bb4
Update rad files
add missing ~LIGHT3B
2023-12-05 17:00:40 +03:00
NightFox 23c059baac
Update rad files 2023-12-05 16:32:30 +03:00
Ivan Avdeev eba28376d9
Merge pull request #686 from w23/stream-E341
Things done during stream E341

- [x] `vk/mod` in logs
- [x] fix NaNites, #685 
- [x] fix double switchable lights, #679
2023-12-04 11:01:14 -08:00
Ivan Avdeev f244aaaddf vk: update TODO 2023-12-04 13:57:06 -05:00
Ivan Avdeev 4fc6db36b4 vk: rt: fix adding switchable/animated light twice
Skip adding animated surfaces as static lights. We'd like them to be
static, but currently there's no distinction between immovable lights
and switchable lights or lights with dynamic emissive value.

Fixes #679
2023-12-04 13:48:12 -05:00
Ivan Avdeev 84f6d7d10b vk: rt: fix reading garbage values out of indirect spec bounds
Indirect specular and diffuse have half frame resolution.
Denoiser code was incorrectly reading past the valid range for indirect
specular values. This was sometimes giving visual glitches at frame
borders.

Fixes #685
2023-12-04 12:14:44 -05:00
Ivan Avdeev 0549822d53 vk: print 'vk/module' in logs 2023-12-04 11:29:38 -05:00
NightFox cdb1532979
Added new rad files
c2a* maps
2023-12-04 00:31:37 +03: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 605647aecc vk: rt: support changing screen resolution
Fixes #343
2023-11-30 13:01:40 -05:00
Ivan Avdeev bde036fc45 vk: find existing gpu scope with the same name
fixes #667
2023-11-30 11:57:15 -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 c9b485f8a7
Merge pull request #671 from w23/stream-E338
Things committed during streams E338-E339

- [x] Allow patching rendermode for func_* entities, fixes #663
- [x] Print out screenshot timings
- [x] Unsuccessfully reset denoiser statistics on discontinuities
2023-11-30 08:09:07 -08:00