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
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
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.
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.
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.
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.
- 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)
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.
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
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
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
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
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.
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.
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.
- 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.
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.
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 `!!`.
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
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
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
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.