float3 UpgradeToneMapPerChannel(float3 color_hdr, float3 color_sdr, float3 post_process_color, float post_process_strength) {
float3 ap1_hdr = max(0, renodx::color::ap1::from::BT709(color_hdr));
float3 ap1_sdr = max(0, renodx::color::ap1::from::BT709(color_sdr));
float3 ap1_post_process = max(0, renodx::color::ap1::from::BT709(post_process_color));
float3 ratio = float3(
UpgradeToneMapRatio(ap1_hdr.r, ap1_sdr.r, ap1_post_process.r),
UpgradeToneMapRatio(ap1_hdr.g, ap1_sdr.g, ap1_post_process.g),
UpgradeToneMapRatio(ap1_hdr.b, ap1_sdr.b, ap1_post_process.b));
float3 color_scaled = max(0, ap1_post_process * ratio);
color_scaled = renodx::color::bt709::from::AP1(color_scaled);
+ float peak_correction = saturate(1.f - renodx::color::y::from::AP1(ap1_post_process));
+ color_scaled = renodx::color::correct::Hue(color_scaled, post_process_color, peak_correction);
return lerp(color_hdr, color_scaled, post_process_strength);
}