SourceDemoRender icon indicating copy to clipboard operation
SourceDemoRender copied to clipboard

SVR uses nonlinear sRGB for frame blending

Open GameChaos opened this issue 2 years ago • 1 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);
    ...
}

GameChaos avatar Aug 13 '23 09:08 GameChaos

very nice, thank you for finding this.

crashfort avatar Aug 14 '23 20:08 crashfort

Thanks a lot for bringing this up again. This is fixed now (https://github.com/crashfort/SourceDemoRender/commit/f03cd1e49c39c82b2d8baa0b5a2e0f4769f3cc3a) 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

crashfort avatar Mar 19 '24 20:03 crashfort

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.

crashfort avatar Mar 19 '24 22:03 crashfort

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

crashfort avatar Mar 19 '24 22:03 crashfort

Ok, pretty off topic but since this is all related to color, above is fixed now in https://github.com/crashfort/SourceDemoRender/commit/667063177bfc1c56e1765b8ce03bb0aa6a815a77.

rgb_css rgb_mpc rgb_mpv stage_css stage_mpc stage_mpv

crashfort avatar Mar 19 '24 23:03 crashfort

Done now in 41.

crashfort avatar Mar 20 '24 15:03 crashfort