vk: rt: linearize kusochki.color/override_color

This commit is contained in:
Ivan Avdeev 2023-12-28 11:21:32 -05:00
parent 310ecff585
commit 46e95f1255
5 changed files with 45 additions and 3 deletions

View File

@ -1087,3 +1087,32 @@ Original:
Our:
`color = sqrt(a*a + b*b)`
There's nothing we can to do `a` only that would make it fake the "original" mixing result.
# 2023-12-28 E353
## Passing colors from all over the place into `trace_simple_blending.glsl`
- color = mm_color * texture_color * geom.vertex_color * alpha
- alpha = mm_color.a * texture_color.a * geom.vertex_color.a
- mm_color = model.color * kusok.material.base_color
- model.color -- already linearized
- kusok.material.base_color = mat->base_color * override_color
- mat->base_color -- specified in .mat files by hand
- [x] Which colorspace should it be specified in?
Currently it is passed in as is, which means that it's accidentally linear.
- override_color -- passed from the engine through `R_RenderDrawOnce()`, called from triapi
- [x] sRGB-γ, should linearize
- texture_color -- just texture sampled color. sRGB-γ vs linear is specified at VkImageView level at loading time
- geom.vertex_color -- barycentric-lerped from vk_vertex[].color
- vk_vertex[].color -- rgba8
- [x] which colorspace? Should be sRGB-γ originally
- [x] Do we need to linearize it? YES
- [x] Before lerping or after? BEFORE -- already done
- Should α be converted from gamma to linear?
- Doing so:
- seems kinda logical -- everything is gamma-space in engine, so it probably should be.
- fixes some 'background' sprites transparency
- makes too-brighs c0a0c beams darker (but kinda too dark imo)
- breaks sprite animation lerping -- now we need 2 native gamma-to-linear functions, wich alpha conv and w/o
As usual -- original sRGB-specialized game art is painfully incompatible with modern linear PBR.
The best way to address it (hopefully w/o breaking too much linear rendering math) remains to be discovered.

View File

@ -1,3 +1,7 @@
# 2023-12-28 E353
- [x] track color spaces when passing colors into shaders
- [ ] validation failure at startup, #723
Longer-term agenda for current season:
- [ ] Better PBR math, e.g.:
- [ ] Black metals: https://github.com/w23/xash3d-fwgs/issues/666

View File

@ -337,6 +337,15 @@ static void sRGBtoLinearVec4(const vec4_t in, vec4_t out) {
out[3] = in[3];
}
static void sRGBAtoLinearVec4(const vec4_t in, vec4_t out) {
out[0] = sRGBtoLinearScalar(in[0]);
out[1] = sRGBtoLinearScalar(in[1]);
out[2] = sRGBtoLinearScalar(in[2]);
// α also needs to be linearized.
out[3] = sRGBtoLinearScalar(in[3]);
}
void RT_FrameAddModel( struct rt_model_s *model, rt_frame_add_model_t args ) {
if (!model || !model->blas)
return;
@ -476,7 +485,7 @@ void RT_FrameAddOnce( rt_frame_add_once_t args ) {
break;
}
Vector4Copy(*args.color, dyn->colors[dyn->geometries_count]);
sRGBAtoLinearVec4(*args.color_srgb, dyn->colors[dyn->geometries_count]);
dyn->geometries[dyn->geometries_count++] = args.geometries[i];
}
}

View File

@ -844,7 +844,7 @@ void R_RenderDrawOnce(r_draw_once_t args) {
RT_FrameAddOnce((rt_frame_add_once_t){
.debug_name = args.name,
.geometries = &geometry,
.color = args.color,
.color_srgb = args.color,
.geometries_count = 1,
.render_type = args.render_type,
});

View File

@ -78,7 +78,7 @@ void RT_FrameAddModel( struct rt_model_s *model, rt_frame_add_model_t args );
typedef struct {
const char *debug_name;
const struct vk_render_geometry_s *geometries;
const vec4_t *color;
const vec4_t *color_srgb;
int geometries_count;
int render_type;
} rt_frame_add_once_t;