crashfort/SourceDemoRender

SVR uses nonlinear sRGB for frame blending

GameChaos opened this issue · 6 comments

Only tested in CS:GO.

Frame blending should be done in linear sRGB, but SVR currently uses nonlinear sRGB leading to darkened blending between some colours and between light and dark areas:
image

Compared with correct blending:
image

Here's the map i used for testing: svr_srgb.zip

My crude fix was done like this:
motion_sample.hlsl

void main(uint3 dtid : SV_DispatchThreadID)
{
    uint2 pos = dtid.xy;

    float4 source_pix = source_texture.Load(dtid);
    source_pix.xyz = pow(max(source_pix.xyz, 0), 2.2);
    dest_texture[pos] += source_pix * mosample_weight;
}

tex2vid.hlsl

void proc(uint3 dtid)
{
    float4 pix = input_texture[dtid.xy];
    pix.xyz = pow(max(pix.xyz, 0), 1.0 / 2.2);
    ...
}

very nice, thank you for finding this.

Thanks a lot for bringing this up again. This is fixed now (f03cd1e) and will be in the next release. This fix became prettier with the introduction of svr_encoder, since there has to be an additional downsampling stage where this fits in naturally.

Below screenshots use different settings, but the point is to show the blending.

Before:
a mp4_snapshot_00 00 684

After:

a mov_snapshot_00 00 417

Do you know why the background boxes under the HUD elements disappear with this? I think it would probably need a different blend equation but I have not been able to figure it out.

This bsp works for CSS if you want to check:
srgb.zip

Edit: This apparently happens with motion blur off too, which is weird because this code doesn't even run in that case.

Never mind, this disappears using the BT709 color space over the BT601 color space.

Ok, pretty off topic but since this is all related to color, above is fixed now in 6670631.

rgb_css
rgb_mpc
rgb_mpv
stage_css
stage_mpc
stage_mpv

Done now in 41.