Skip to content

Commit 817a3a9

Browse files
MajorPainTheCactusLibretroAdmin
authored andcommitted
HDR: rename PaperWhiteNits to BrightnessNits, remove unified scanline bloom
- Rename shader UBO member PaperWhiteNits to BrightnessNits in HLSL and GLSL built-in HDR shaders - Rename slang reflection semantic from PaperWhiteNits to BrightnessNits for custom shaders - Remove UNIFIED_SCANLINE_BLOOM code path and kLuminanceWeights from Vulkan HDR shader, keeping per-channel bloom only - Update Brightness menu description with alternative calibration tip - Recompile Vulkan HDR SPIR-V
1 parent be954ed commit 817a3a9

7 files changed

Lines changed: 1337 additions & 1394 deletions

File tree

gfx/drivers/d3d_shaders/hdr_sm5.hlsl.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SRC(
66
float4x4 modelViewProj;
77
float2 SourceSize;
88
float2 OutputSize;
9-
float paper_white_nits; /* 200.0f */
9+
float brightness_nits; /* 200.0f */
1010
float max_nits; /* 1000.0f */
1111
uint subpixel_layout; /* 0 */
1212
float scanlines; /* 1.0f */
@@ -192,13 +192,13 @@ float3 HDR10ToscRGB(float3 hdr10Color)
192192
}
193193
/* END Converted from (Copyright (c) Microsoft Corporation - Licensed under the MIT License.) https://github.com/microsoft/Xbox-ATG-Samples/tree/master/Kits/ATGTK/HDR */
194194

195-
float3 InverseTonemap(const float3 sdr_linear, const float max_nits, const float paper_white_nits)
195+
float3 InverseTonemap(const float3 sdr_linear, const float max_nits, const float brightness_nits)
196196
{
197197
const float input_val = max(sdr_linear.r, max(sdr_linear.g, sdr_linear.b));
198198

199199
if (input_val < 0.0001f) return sdr_linear;
200200

201-
const float peak_ratio = max_nits / paper_white_nits;
201+
const float peak_ratio = max_nits / brightness_nits;
202202

203203
const float numerator = input_val;
204204
const float denominator = 1.0f - input_val * (1.0f - (1.0f / peak_ratio));
@@ -286,12 +286,12 @@ float4 To2020(const float4 sdr_linear)
286286

287287
float3 HDR(const float3 sdr_linear)
288288
{
289-
return InverseTonemap(sdr_linear, global.max_nits, global.paper_white_nits);
289+
return InverseTonemap(sdr_linear, global.max_nits, global.brightness_nits);
290290
}
291291

292292
float4 HDR(const float4 sdr_linear)
293293
{
294-
const float3 hdr_linear = InverseTonemap(sdr_linear.rgb, global.max_nits, global.paper_white_nits);
294+
const float3 hdr_linear = InverseTonemap(sdr_linear.rgb, global.max_nits, global.brightness_nits);
295295

296296
return float4(hdr_linear, sdr_linear.a);
297297
}
@@ -304,7 +304,7 @@ float3 LinearToSignal(const float3 linear_colour)
304304

305305
float3 HDR10(const float3 hdr_linear)
306306
{
307-
const float3 pq_input = hdr_linear * (global.paper_white_nits / kMaxNitsFor2084);
307+
const float3 pq_input = hdr_linear * (global.brightness_nits / kMaxNitsFor2084);
308308

309309
const float3 hdr10 = LinearToST2084(max(pq_input, 0.0f));
310310

@@ -313,7 +313,7 @@ float3 HDR10(const float3 hdr_linear)
313313

314314
float4 HDR10(const float4 hdr_linear)
315315
{
316-
const float3 pq_input = hdr_linear.rgb * (global.paper_white_nits / kMaxNitsFor2084);
316+
const float3 pq_input = hdr_linear.rgb * (global.brightness_nits / kMaxNitsFor2084);
317317

318318
const float3 hdr10 = LinearToST2084(max(pq_input, 0.0f));
319319

@@ -516,7 +516,7 @@ float4 PSMain(PSInput input) : SV_TARGET
516516
* scRGB units: 1.0 = 80 nits. */
517517
float3 linear_col = Scanlines(input.texcoord);
518518

519-
return float4(linear_col * (global.paper_white_nits / kscRGBWhiteNits), 1.0f);
519+
return float4(linear_col * (global.brightness_nits / kscRGBWhiteNits), 1.0f);
520520
}
521521
else
522522
{

gfx/drivers/vulkan_shaders/hdr.frag

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ const float kPi = 3.1415926536;
1515
const float kEuler = 2.718281828459;
1616
const float kMax = 1.0;
1717

18-
#define UNIFIED_SCANLINE_BLOOM
1918

2019
const float kBeamWidth = 0.5;
2120

22-
const vec3 kLuminanceWeights = vec3(0.2126, 0.7152, 0.0722);
2321

2422
const uint kChannelMask = 3u;
2523
const uint kFirstChannelShift = 2u;
@@ -188,7 +186,7 @@ vec3 LinearToSignal(const vec3 linear_colour)
188186

189187
vec3 HDR10(const vec3 hdr_linear)
190188
{
191-
vec3 pq_input = hdr_linear * vec3(global.PaperWhiteNits / kMaxNitsFor2084);
189+
vec3 pq_input = hdr_linear * vec3(global.BrightnessNits / kMaxNitsFor2084);
192190

193191
vec3 hdr10 = LinearToST2084(max(pq_input, vec3(0.0f)));
194192

@@ -197,7 +195,7 @@ vec3 HDR10(const vec3 hdr_linear)
197195

198196
vec4 HDR10(const vec4 hdr_linear)
199197
{
200-
vec3 pq_input = hdr_linear.rgb * vec3(global.PaperWhiteNits / kMaxNitsFor2084);
198+
vec3 pq_input = hdr_linear.rgb * vec3(global.BrightnessNits / kMaxNitsFor2084);
201199

202200
vec3 hdr10 = LinearToST2084(max(pq_input, vec3(0.0f)));
203201

@@ -258,30 +256,6 @@ vec3 ScanlineColour(const vec2 tex_coord,
258256
float distance_adjusted = max(0.0, raw_distance);
259257
float effective_distance = distance_adjusted * 2.0;
260258

261-
#ifdef UNIFIED_SCANLINE_BLOOM
262-
/* Unified bloom: compute a single horizontal interpolation from luminance
263-
* so the scanline envelope is shared across all channels in the phosphor
264-
* triad, preventing colour shifts from per-channel bloom differences. */
265-
float lum_0 = dot(signal_0, kLuminanceWeights);
266-
float lum_1 = dot(signal_1, kLuminanceWeights);
267-
float lum_horiz_interp = Bezier(narrowed_source_pixel_offset, BeamControlPoints(beam_attack, lum_0 > lum_1));
268-
float beam_intensity = clamp(mix(lum_0, lum_1, lum_horiz_interp), 0.0, 1.0);
269-
270-
float beam_width = mix(scanline_min, scanline_max, beam_intensity);
271-
float scanline_dist = clamp(effective_distance / beam_width, 0.0, 1.0);
272-
vec4 control_points = vec4(1.0, 1.0, beam_intensity * scanline_attack, 0.0);
273-
float envelope = Bezier(scanline_dist, control_points);
274-
275-
for(int ch = 0; ch < 3; ch++)
276-
{
277-
float horiz_interp = Bezier(narrowed_source_pixel_offset, BeamControlPoints(beam_attack, signal_0[ch] > signal_1[ch]));
278-
float signal_channel = mix(signal_0[ch], signal_1[ch], horiz_interp);
279-
280-
result[ch] = envelope * signal_channel;
281-
}
282-
#else
283-
/* Per-channel bloom: each channel computes its own scanline envelope based on
284-
* its individual brightness (models independent electron gun bloom). */
285259
for(int ch = 0; ch < 3; ch++)
286260
{
287261
float horiz_interp = Bezier(narrowed_source_pixel_offset, BeamControlPoints(beam_attack, signal_0[ch] > signal_1[ch]));
@@ -298,7 +272,6 @@ vec3 ScanlineColour(const vec2 tex_coord,
298272

299273
result[ch] = luminance * signal_channel;
300274
}
301-
#endif
302275

303276
return result;
304277
}
@@ -418,15 +391,15 @@ void main()
418391
{
419392
/* scRGB mode: sRGB to linear for scRGB / HDR16 swapchain.
420393
* Scale by MaxNits / kscRGBWhiteNits because scRGB 1.0 = 80 nits.
421-
* Using MaxNits (not PaperWhiteNits) so the SDR UI fills the
394+
* Using MaxNits (not BrightnessNits) so the SDR UI fills the
422395
* display's native range, preserving tonal balance uniformly. */
423396
if((global.Scanlines > 0.0) && (global.OutputSize.y > 240.0 * 4.0))
424397
{
425398
/* Scanlines() returns linear Rec.709 with mask already applied in Rec.709 space.
426399
* scRGB units: 1.0 = 80 nits. */
427400
vec3 linear = Scanlines(vTexCoord);
428401

429-
FragColor = vec4(linear * (global.PaperWhiteNits / kscRGBWhiteNits), 1.0);
402+
FragColor = vec4(linear * (global.BrightnessNits / kscRGBWhiteNits), 1.0);
430403
}
431404
else
432405
{

0 commit comments

Comments
 (0)