[Feature Request]: Rec.709 Gamma Curve for post_process.frag
Author: XgarhontXCreated Sep 30, 2026Updated Sep 30, 2026
Checklist
- I have searched for a similar issue in this repository and did not find one.
Description
The ability to use the Rec.709 gamma curve to lower shadows like real PS4 output.
- This requires a new user settings bool.
- For UI, I guess inside the
CTRL+F10will do? - But since games are purposefully graded with Rec.709 gamma, hopefully there's a better spot!
- For UI, I guess inside the
- The old
CTRL+F10gamma slider can stay.- With the actual function, the default should no longer be
1.1. It should be1.0for sRGB (and for standard 2.2 decode mismatch).
- With the actual function, the default should no longer be
Here would be post_process.frag:
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#version 450
layout (location = 0) in vec2 uv;
layout (location = 0) out vec4 color;
layout (binding = 0) uniform sampler2D texSampler;
layout (push_constant) uniform settings {
float gamma;
bool hdr;
bool srgb_input;
bool is_rec709; // (new user setting)
} pp;
// sRGB encoding with user gamma value
const float cutoff = 0.0031308, a = 1.055, b = 0.055, d = 12.92;
vec3 linear_to_sRGB(vec3 rgb) { // (formerly gamma)
return mix(
a * pow(rgb, vec3(1.0 / (2.4 + 1.0 - pp.gamma))) - b,
d * rgb / pp.gamma,
lessThan(rgb, vec3(cutoff))
);
}
// Exact inverse of gamma() at unit gamma, for buffers that are sRGB encoded but must be sampled
// through a UNORM view because Vulkan has no sRGB variant of the 10-bit format.
vec3 sRGB_to_linear(vec3 rgb) { // (formerly degamma)
return mix(
pow(max(rgb + b, 0.0) / a, vec3(2.4)),
rgb / d,
lessThan(rgb, vec3(d * cutoff))
);
}
// Rec.709 encoding function
// \left\{x<0.018:4.5x,1.099x^{0.45}-0.099\right\}
vec3 linear_to_rec709(vec3 rgb) {
return mix(
1.099 * pow(rgb, vec3(0.45)) - 0.099,
4.5 * rgb,
lessThan(rgb, vec3(0.018))
);
}
void main() {
vec4 color_linear = texture(texSampler, uv);
if (pp.hdr) {
color = color_linear;
} else {
// optional linearize
if (pp.srgb_input) color_linear.rgb = sRGB_to_linear(color_linear.rgb);
// apply Rec.709 encoding if enabled
if (pp.is_rec709) {
color_linear.rgb = linear_to_rec709(color_linear.rgb); // encode weak
color_linear.rgb = sRGB_to_linear(color_linear.rgb); // decode strong (which lowers shadows)
}
// gamma for SDR
color = vec4(linear_to_sRGB(color_linear.rgb), color_linear.a);
}
}Reason
The Primary Reason
- Adding this feature will more accurately emulate the presentation of the real PS4 for all games.
Old issue regarding contrast for Bloodborne. https://github.com/shadps4-emu/shadPS4/issues/1725
- Implementing the curve should be the exact match to PS4/PS5, truly closing this issue.
Examples
Call of Duty: Black Ops 3
- The game has this feature for the PC port because it was originally graded with it for PS4 & Xbox One.
- Here is the
.csodump (via RenoDX & Luma) decompiled to HLSL of the fullscreen pixel shader drawn right before present ifHDTV (rec.709)is selected.- It's different from what I'm proposing for
post_process.fragbecause the input is always sRGB. (You can implement it like this, but the idk what happens for the gamma slider.)
- It's different from what I'm proposing for
// ---- Created with 3Dmigoto v1.3.16 on Thu Jul 31 09:17:17 2025
SamplerState bilinearClamp_s : register(s0);
Texture2D<float4> codeTexture0 : register(t0);
// 3Dmigoto declarations
#define cmp -
void main(
float2 v0 : TEXCOORD0,
float4 v1 : SV_POSITION0,
out float3 o0 : SV_TARGET0
) {
discard;
float4 r0,r1,r2;
uint4 bitmask, uiDest;
float4 fDest;
r0.xyz = codeTexture0.Sample(bilinearClamp_s, v0.xy).xyz;
// decode sRGB to linear
r1.xyz = float3(0.0549999997,0.0549999997,0.0549999997) + r0.xyz;
r1.xyz = float3(0.947867334,0.947867334,0.947867334) * r1.xyz;
r1.xyz = log2(r1.xyz);
r1.xyz = float3(2.4000001,2.4000001,2.4000001) * r1.xyz;
r1.xyz = exp2(r1.xyz);
r2.xyz = cmp(float3(0.0404499993,0.0404499993,0.0404499993) >= r0.xyz);
r0.xyz = float3(0.0773993805,0.0773993805,0.0773993805) * r0.xyz;
r0.xyz = r2.xyz ? r0.xyz : r1.xyz;
// encode linear to Rec.709
r1.xyz = log2(r0.xyz);
r1.xyz = float3(0.449999988,0.449999988,0.449999988) * r1.xyz;
r1.xyz = exp2(r1.xyz);
r1.xyz = r1.xyz * float3(1.09899998,1.09899998,1.09899998) + float3(-0.0989999995,-0.0989999995,-0.0989999995);
r2.xyz = cmp(r0.xyz < float3(0.0179999992,0.0179999992,0.0179999992));
r0.xyz = float3(4.5,4.5,4.5) * r0.xyz;
o0.xyz = r2.xyz ? r0.xyz : r1.xyz;
return;
}Hatsune Miku: Project DIVA Future Tone
- Here is the PC port (MegaMix+). It is sRGB.
- Here is shadPS4 with the
CTRL+F10Brightness slider (pp.gamma) at1.0.
- Here is the real PS4 via "SHARE" button screenshot.
- Here is the PC port modded with the same math proposed for
post_process.frag.
// Rec709 correction
#if CUSTOM_HDTVREC709_1 == 1
x = EncodeRec709(x); // linear to Rec709
x = DecodeSrgb(x); // sRGB to linear
#endifSource: shadps4-emu/shadPS4