Commit Graph

4520 Commits

Author SHA1 Message Date
Ivan Avdeev e12b2c47b4 vk: rt: added minimal distance for legacy soft blending
Only engage soft particles/blending after a certain distance. Makes
certain see-beams-through-weapons visual glitches disappear.

Engages soft particles with a smoothstep so the don't immediately pop up
after a certain distance, rather appear gradually.
2024-01-19 12:02:26 -05:00
Ivan Avdeev 6ee8af040e vk: throttle zero normal messages 2024-01-19 11:42:15 -05:00
Ivan Avdeev 073dbc55f8 vk: fixup studio model zero normal printing 2024-01-19 11:39:26 -05:00
Ivan 'provod' Avdeev 344c804468 vk: remove extra includes 2024-01-19 11:34:44 -05:00
Ivan 'provod' Avdeev 5f3a0c233b vk: rt: investigate more nans
Found that some studio models end up producing zero-length normals. See #731
2024-01-19 11:34:31 -05:00
Ivan Avdeev 6a7cb77809 vk: shave todo yak 2024-01-18 11:37:16 -05:00
Ivan Avdeev 0e4e754fdb vk: cleanup todo a bit x2 2024-01-18 11:34:07 -05:00
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 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 6ffaad02f2
Merge pull request #724 from w23/stream-E355
Stuff done during stream E355

- [x] fix accidental translucency for alpha-masked geometries: #721
2024-01-01 10:25:36 -08:00