Commit Graph

4089 Commits

Author SHA1 Message Date
Ivan Avdeev 4158234fb2 rename ktx_ to ktx2_ for consistency 2023-10-12 12:51:58 -04:00
Ivan Avdeev 4efbb11178 imagelib: attempt to fix ktx2 compilation in C90 mode 2023-10-12 12:46:50 -04:00
Ivan Avdeev 90119ae84a imagelib: add rudimentary KTX2 support
It only does a very basic header validation, and passes the entire file
as PF_KTX2_RAW format. This is to simplify KTX2 reading in ref_vk and
trying out different formats. KTX2 has support for >200 format, and
passing all of them through PF_ types is a non-starter.

The plan is to figure out which formats we want to support, and add
their support to imagelib/ktx2 incrementally, leaving the rest as
PF_KTX2_RAW, so ref_vk still can use them.
2023-10-12 12:38:35 -04:00
Ivan Avdeev 726fcee3f7
Merge pull request #593 from w23/materials-table
Materials table and friends

- [ ] KTX2 #154
  - [x] proof of concept
  - [x] proper alignment for blocks (validation complains)
- [ ] texture leaks: #594 
  - [x] investigate
- [x] `inherit`/`use`
- [x] Fix #211 
  - [x] make materials table
  - [ ] ~~make materials by-name lookup independent of texture table, stop doing dummy textures~~ moved to #601 
- [ ] normalmap glitches, #595
  - [x] investigated, seems to be offline normalization vs bit depth/precision issue; needs offline changes
2023-10-12 08:43:49 -07:00
Ivan Avdeev 9ca7aad276 vk: align textures to texel block size on upload
fixes occasional validation woes
2023-10-10 14:02:49 -04:00
Ivan Avdeev 5ba5fc4831 vk: fixup build after backmerge 2023-10-10 14:00:47 -04:00
NightFox ecdb68370b
Merge branch 'vulkan' into materials-table 2023-10-10 20:32:04 +03:00
Ivan Avdeev 7396403984 vk: materials: allow inheriting previously defined materials
`"inherit" "debug_test"` will replace all fields for the current
material with ones from material named "debug_test".
`"inherit"` should be specified before any material fields, except for
selectors like "new", "for" and "for_rendermode".
2023-10-10 13:27:10 -04:00
Ivan Avdeev 82dea7a86b
Merge pull request #597 from w23/srgb-gamma
sRGB-γ all the things

- [x] Makes all textures SRGB by default
- [x] For traditional renderer: convert back to SRGB space like it's 1998 again
  - [x] Make different `VkImageView`s, for linear (trad) and SRGB (rt) to avoid extra conversion
    - see https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#formats-compatibility-classes
supported surface formats, and also whether the image can be used as a storage destination in compute shader.
- [x] Improve `view_unorm` handling:
  - [x] Don't create a separate view for natively `UNORM`
  - [x] Create fallback 
- [x] Use "native" hint for pbr base_color
- [x] Remove `test_val` from shaders
- [x] Do model and material colors srgb-linear conversion in C
- [x] Investigate lighting brightness
  - Nihrena neponyatno. 

Problems caused by this amazing change:
- Undesired interpolation artifacts: #599 (see discussion below).
- Dark places are too dark (caused by more correct linear-to-sRGB conversion that differs from the fast one for smaller values).
- Lighting looks a bit different (probably has the same cause as above)
2023-10-10 09:47:25 -07:00
Ivan Avdeev fc36fb7c13 vk: create unorm image view only if asked and needed
Do not create unorm image view:
- if not asked
- already has unorm format
- format has no meaningful unorm counterpart
2023-10-10 12:18:58 -04:00
Ivan Avdeev 7b69988e41 vk: materials: use native color hint explicitly to avoid enforcing gamma 2023-10-10 12:08:25 -04:00
Ivan Avdeev bf403027c6 vk: rt: do linear vertex_color interpolation 2023-10-10 12:01:39 -04:00
Ivan Avdeev fadde2ea0d vk: rt: convert more engine-supplied colors from sRGB to linear
- model.color
- vertex_color
2023-10-10 11:56:42 -04:00
Ivan 'provod' Avdeev 4fa614d35b vk: rt: do not use fast srgb-linear conversion
FAST mode is incorrect for low values and leads to visible rendering artifacts.
2023-10-09 19:49:54 -04:00
Ivan Avdeev d76d6429d0 vk: rt: ensure that base_color_a is stored in sRGB-γ
Storing it linearly was a mistake: it is 8-bit only, and lacks enough
precision for dark values. It also doesn't really need any more
precision, and should be limited to 0..1 range.

Therefore, it makes sense to treat it as sRGB explicitly.
2023-10-09 14:51:29 -04:00
Ivan Avdeev 7bfba01954 vk: rt: add test for srgb-vs-linear model color 2023-10-09 14:51:07 -04:00
Ivan Avdeev 9843f53cde vk: rt: recreate images on format change 2023-10-09 14:48:50 -04:00
Ivan Avdeev 57093d7198 vk: remove extra stuff, add comments about SRGB swapchain 2023-10-09 13:13:11 -04:00
Ivan Avdeev 2ec92eea0d vk: add a bunch of profiler scopes to rt rendering 2023-10-09 13:02:04 -04:00
Ivan Avdeev 3b40469a87 vk: fix validation sync error on changelevel 2023-10-09 12:48:38 -04:00
Ivan Avdeev 1d2da5831e vk: image: make a raw unorm image view for trad renderer
Traditional renderer operates in sRGB-γ space (as everyone was in 199x).
Making vulkan textures explicitly SRGB for RT renderer breaks color for
trad rendere. Make sure trad renderer still has raw SRGB-unaware texture
sampling.

Adds an UNORM image view for all relevant SRGB textures, and uses them
exclusively for trad renderer. RT still gets proper SRGB views.

Also rename XVK_ to R_Vk for images
2023-10-09 12:39:12 -04:00
Ivan Avdeev c5bbcae242
Merge pull request #596 from a1batross/vulkan
Merge upstream

It's me again, bringing you changes from upstream master branch.

No really interesting changes yet, mostly code refactoring, bug fixes, optimizations.
* We finally migrated all cvars to static allocation, making it's easier for CPU to access cvar values. I do not recommend migrating for renderers yet because of known bug with `GLCONFIG` cvars.
* In OpenGL renderer we started to use `GenTextures` call instead of directly binding arbitrary texture IDs, which also fixed few bugs with overlay programs.
* I probably finally fixed the bug where the engine crashes on startup on Linux, somewhere deep in SDL. At least, I haven't seen it for a while.
* We also finally allow C99 code in the engine. I don't think engine will be ported to new old standard overnight, it's just now fine for new code. 
* We support `.pk3dir`. It's a Quake engine's convention to allow mounting directories that end with `.pk3dir`, as if they were archives. It simplifies development process, where current dev version of assets could be in `pk3dir` and packaged into `pk3` for release.
* I added simple tool called `xar` that unpacks data from `.pak`, `.pk3` and `.wad` archives using `filesystem_stdio`.
2023-10-06 21:33:42 -07:00
Alibek Omarov 3f505103e1 ref: vk: do not create cl_righthand cvar 2023-10-07 00:53:15 +03:00
Alibek Omarov 2c520a6a55 ref: vk: enable compiling with older Vulkan headers 2023-10-07 00:53:15 +03:00
Alibek Omarov fcc6bba88a Merge upstream/master 2023-10-07 00:53:04 +03:00
Ivan Avdeev 9b9e89adec vk: make all texture samplers return values in linear space
Make sure that all SRGB-gamma textures are marked with SRGB format (this
includes all the original textues, 8bit PNG textues). All other
textures (roughness, metallic, normal maps) are linear (UNORM).

Trust KTX2 texture that they store in the correct colorspace.

Then we can just sample textures w/o SRGBtoLINEAR'izing them. Supposedly
this is better because of hw interpolation in the correct colorspace.

This is a bit experimental because Compressonator can't really into
BC7_SRGB, which is sad. And also we need to re-gamma all the textures
for the gamma/srgb-unaware traditional renderer.
2023-10-06 15:06:44 -04:00
Ivan Avdeev 60f83245ee vk: rt: make base_color_a linear-space
Convert from gamma to linear at the point where we read from texture.

Prerequisite for making textures in a right colorspace.
2023-10-06 13:51:32 -04:00
Ivan Avdeev 41ac5fa0eb vk: fix printing 64-bit numbers in x86 linux 2023-10-06 13:13:31 -04:00
Ivan Avdeev 96e9ef20ab vk: rt: make normalmaps switchable between xyz.png and xy.ktx2
They have slightly different incompatible encodings. Switch between them
using #define at build time.

Old png code can be removed when we fully switch to KTX2.
2023-10-06 13:05:42 -04:00
Alibek Omarov a738b2a50b ref: restore missing PARM_TEX_MEMORY RenderAPI parameter 2023-10-06 19:24:02 +03:00
NightFox 56737fd05f
Merge pull request #591 from w23/everything-is-smooth
vk: patch: allow smoothing entire brush model
2023-10-05 22:00:39 +03:00
Ivan Avdeev ab53aae359 vk: textures: preliminary KTX2 support
Loads something. Not everything. Not everything correctly.
Doesn't do validity checks.

Makes colorspace (srgb gamma vs linear) inconsistent between textures
(ktx has correct srgb-vs-unorm, all is unorm (but srgb gamma
semantically) in png)
Makes normals inconsistent too (.xy in ktx, .xyz in png)

related #154
2023-10-05 14:23:46 -04:00
Ivan Avdeev 7e3f8785f7 vk: fix normalmap glitches
Was triggered by renormalizing normal z when applying normal scale.
Not sure why exactly, though, the math checks out.

Doing it a bit differently solves the issue.

Fixes #595
2023-10-05 12:48:48 -04:00
Ivan Avdeev 9b90e920a7 vk: add textures counts/size to metrics
Also split frame flame graphs and metric graphs to different `r_speeds`
bits.

related to #594
2023-10-05 12:20:07 -04:00
Alibek Omarov 34fa1b5ec8 engine: remove PORT_CLIENT, we should randomize client port by default, thus allowing easier connections from same IP address 2023-10-05 11:06:04 +03:00
NightFox e04a19a0af
Merge pull request #559 from w23/bluenoise
vk: textures: add blue noise textures
2023-10-04 22:55:53 +03:00
NightFox 206fd528d8
Merge branch 'vulkan' into bluenoise 2023-10-04 22:44:49 +03:00
Ivan Avdeev 0d6f6d26af vk: material: add material table independent of texture table
It still reuses texture table for name lookup for now.
2023-10-03 12:48:26 -04:00
Alibek Omarov 2fdd080eef mainui: update 2023-10-02 19:31:35 +03:00
Ivan Avdeev 6bfa4c90fa vk: brush: assign white texture for kRenderTransColor
kRenderTransColor mode strips geometry of its texture and makes it solid
color. Previously we were noticing this rendermode late, and failed to
update the textures.

Now we depend on reading this rendermode from map entities, and
pre-assigning correct (white) textures on load.

Assumes that rendermode doesn't change at runtime for brush models.

Fixes #528
2023-10-02 11:39:00 -04:00
Ivan Avdeev 1bbcf44864 vk: patch: allow smoothing entire brush model
fixes #589
2023-10-02 11:18:22 -04:00
Ivan Avdeev b740e0848d
Merge pull request #590 from 0x4E69676874466F78/vulkan
update patches
2023-10-02 07:59:31 -07:00
NightFox bdc66ba52b
Merge branch 'vulkan' into vulkan 2023-10-02 17:58:26 +03:00
Ivan Avdeev 737cd944bb
Merge pull request #572 from w23/lol-materials
- [x] Pass material reference via geom/render API
- [x] Show original textures for traditional renderer, #571
- [x] Remove old material type flags
  - [x] ~~Move sky surfaces to a separate BLAS~~ Remove `SURF_DRAWSKY` from geometries completely #474 
  - [x] **REVERT** `SURF_DRAWSKY` changes. Such surfaces still need to be "drawn" to hide geometry behind it (see comments).
  - [x] Chrome material: have an explicit material for it
    - [x] This needs vk_texture vs vk_material index decoupling
- [x] Assess #577
- [x] Improve paths #578 
  - [x] `pbr/maps/c0a0a.bsp/c0a0a.bsp.mat` -> `pbr/maps/c0a0a.bsp/c0a0a.mat`
  - [x] `pbr/halflife.wad/halflife.wad.mat` -> `pbr/halflife.wad/halflife.mat`
  - [x] Rename files in PBR repo for the above
  - [x] `luchiki/maps/c0a0.bsp.patch` -> `luchiki/maps/c0a0.patch`
  - [x] Rename patch files too
  - [x] Same for spr,mdl
  - [x] Rename
- [x] Pass material mode directly, instead of render type
- [x] Advanced material patching/selection
  - [x] Need a few advanced selection examples
    - [x] #317
    - [x] стёкла у костюма (??)
  - [x] #526
  - [x] #577
  - [x] #213
2023-10-02 07:54:10 -07:00
NightFox bd98fdd1d7
update patches 2023-10-02 01:46:47 +03:00
Ivan Avdeev 8ff89bd5ef vk: materials: add rendermode-specific overrides
Example:
```c1a0d.mat
{
	"for_rendermode" "kRenderTransTexture"
	"for" "table2"
	"basecolor_map" "/colors/white.png"
	"metal_map" "/colors/white.png"
	"roughness_map" "/colors/black.png"
}
```

Fixes #213
2023-09-29 13:59:27 -04:00
Ivan Avdeev 4e01947b6b vk: fix crashing on reloading materials
Needed to drop entity data cache before clearing studio model cache

Fixes #577
2023-09-29 13:02:51 -04:00
Ivan Avdeev e97691b27c vk: patch: allow mapping texture to materials for brush entities
```
{
	"_xvk_ent_id" "39"
	"_xvk_map_material" "generic028 mirror"
}
```

NOTES:
- might severely degrade performance in some cases/under debug as we're
  doing N^2 search with strcmp for rendered entities.
2023-09-29 12:48:32 -04:00
Ivan Avdeev 7839792964 vk: materials: fix bsp/mat file extension culling 2023-09-29 12:39:36 -04:00
Alibek Omarov 95f87e24ee ref: soft: do not register cl_righthand cvar 2023-09-29 13:45:24 +03:00