mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-21 22:32:31 +08:00
Scale SDR content to SDR whitelevel when HDR is enabled
This commit is contained in:
Executable → Regular
+292
-134
@@ -1,134 +1,292 @@
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
|
||||
//
|
||||
//
|
||||
//
|
||||
// Input signature:
|
||||
//
|
||||
// Name Index Mask Register SysValue Format Used
|
||||
// -------------------- ----- ------ -------- -------- ------- ------
|
||||
// SV_POSITION 0 xyzw 0 POS float
|
||||
// TEXCOORD 0 xy 1 NONE float
|
||||
// COLOR 0 xyzw 2 NONE float xyzw
|
||||
//
|
||||
//
|
||||
// Output signature:
|
||||
//
|
||||
// Name Index Mask Register SysValue Format Used
|
||||
// -------------------- ----- ------ -------- -------- ------- ------
|
||||
// SV_TARGET 0 xyzw 0 TARGET float xyzw
|
||||
//
|
||||
//
|
||||
// Level9 shader bytecode:
|
||||
//
|
||||
ps_2_0
|
||||
dcl t1
|
||||
mov oC0, t1
|
||||
|
||||
// approximately 1 instruction slot used
|
||||
ps_4_0
|
||||
dcl_input_ps linear v2.xyzw
|
||||
dcl_output o0.xyzw
|
||||
mov o0.xyzw, v2.xyzw
|
||||
ret
|
||||
// Approximately 2 instruction slots used
|
||||
#endif
|
||||
|
||||
const BYTE g_main[] =
|
||||
{
|
||||
68, 88, 66, 67, 226, 124,
|
||||
10, 63, 141, 181, 49, 167,
|
||||
218, 135, 248, 147, 77, 222,
|
||||
95, 123, 1, 0, 0, 0,
|
||||
52, 2, 0, 0, 6, 0,
|
||||
0, 0, 56, 0, 0, 0,
|
||||
132, 0, 0, 0, 196, 0,
|
||||
0, 0, 64, 1, 0, 0,
|
||||
140, 1, 0, 0, 0, 2,
|
||||
0, 0, 65, 111, 110, 57,
|
||||
68, 0, 0, 0, 68, 0,
|
||||
0, 0, 0, 2, 255, 255,
|
||||
32, 0, 0, 0, 36, 0,
|
||||
0, 0, 0, 0, 36, 0,
|
||||
0, 0, 36, 0, 0, 0,
|
||||
36, 0, 0, 0, 36, 0,
|
||||
0, 0, 36, 0, 0, 2,
|
||||
255, 255, 31, 0, 0, 2,
|
||||
0, 0, 0, 128, 1, 0,
|
||||
15, 176, 1, 0, 0, 2,
|
||||
0, 8, 15, 128, 1, 0,
|
||||
228, 176, 255, 255, 0, 0,
|
||||
83, 72, 68, 82, 56, 0,
|
||||
0, 0, 64, 0, 0, 0,
|
||||
14, 0, 0, 0, 98, 16,
|
||||
0, 3, 242, 16, 16, 0,
|
||||
2, 0, 0, 0, 101, 0,
|
||||
0, 3, 242, 32, 16, 0,
|
||||
0, 0, 0, 0, 54, 0,
|
||||
0, 5, 242, 32, 16, 0,
|
||||
0, 0, 0, 0, 70, 30,
|
||||
16, 0, 2, 0, 0, 0,
|
||||
62, 0, 0, 1, 83, 84,
|
||||
65, 84, 116, 0, 0, 0,
|
||||
2, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
2, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 82, 68, 69, 70,
|
||||
68, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 28, 0,
|
||||
0, 0, 0, 4, 255, 255,
|
||||
0, 1, 0, 0, 28, 0,
|
||||
0, 0, 77, 105, 99, 114,
|
||||
111, 115, 111, 102, 116, 32,
|
||||
40, 82, 41, 32, 72, 76,
|
||||
83, 76, 32, 83, 104, 97,
|
||||
100, 101, 114, 32, 67, 111,
|
||||
109, 112, 105, 108, 101, 114,
|
||||
32, 49, 48, 46, 49, 0,
|
||||
73, 83, 71, 78, 108, 0,
|
||||
0, 0, 3, 0, 0, 0,
|
||||
8, 0, 0, 0, 80, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 3, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
15, 0, 0, 0, 92, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 3, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
3, 0, 0, 0, 101, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 3, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
15, 15, 0, 0, 83, 86,
|
||||
95, 80, 79, 83, 73, 84,
|
||||
73, 79, 78, 0, 84, 69,
|
||||
88, 67, 79, 79, 82, 68,
|
||||
0, 67, 79, 76, 79, 82,
|
||||
0, 171, 79, 83, 71, 78,
|
||||
44, 0, 0, 0, 1, 0,
|
||||
0, 0, 8, 0, 0, 0,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
3, 0, 0, 0, 0, 0,
|
||||
0, 0, 15, 0, 0, 0,
|
||||
83, 86, 95, 84, 65, 82,
|
||||
71, 69, 84, 0, 171, 171
|
||||
};
|
||||
#if 0
|
||||
//
|
||||
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
|
||||
//
|
||||
//
|
||||
// Buffer Definitions:
|
||||
//
|
||||
// cbuffer Constants
|
||||
// {
|
||||
//
|
||||
// float scRGB_output; // Offset: 0 Size: 4
|
||||
// float SDR_whitelevel; // Offset: 4 Size: 4
|
||||
// float HDR_whitelevel; // Offset: 8 Size: 4 [unused]
|
||||
// float maxCLL; // Offset: 12 Size: 4 [unused]
|
||||
// float4 Yoffset; // Offset: 16 Size: 16 [unused]
|
||||
// float4 Rcoeff; // Offset: 32 Size: 16 [unused]
|
||||
// float4 Gcoeff; // Offset: 48 Size: 16 [unused]
|
||||
// float4 Bcoeff; // Offset: 64 Size: 16 [unused]
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// Resource Bindings:
|
||||
//
|
||||
// Name Type Format Dim HLSL Bind Count
|
||||
// ------------------------------ ---------- ------- ----------- -------------- ------
|
||||
// Constants cbuffer NA NA cb0 1
|
||||
//
|
||||
//
|
||||
//
|
||||
// Input signature:
|
||||
//
|
||||
// Name Index Mask Register SysValue Format Used
|
||||
// -------------------- ----- ------ -------- -------- ------- ------
|
||||
// SV_POSITION 0 xyzw 0 POS float
|
||||
// TEXCOORD 0 xy 1 NONE float
|
||||
// COLOR 0 xyzw 2 NONE float xyzw
|
||||
//
|
||||
//
|
||||
// Output signature:
|
||||
//
|
||||
// Name Index Mask Register SysValue Format Used
|
||||
// -------------------- ----- ------ -------- -------- ------- ------
|
||||
// SV_TARGET 0 xyzw 0 TARGET float xyzw
|
||||
//
|
||||
//
|
||||
// Constant buffer to DX9 shader constant mappings:
|
||||
//
|
||||
// Target Reg Buffer Start Reg # of Regs Data Conversion
|
||||
// ---------- ------- --------- --------- ----------------------
|
||||
// c0 cb0 0 1 ( FLT, FLT, FLT, FLT)
|
||||
//
|
||||
//
|
||||
// Level9 shader bytecode:
|
||||
//
|
||||
ps_2_0
|
||||
def c1, 0.0125000002, 1, 0, 0
|
||||
dcl t1
|
||||
mul r0.w, c0.x, c0.x
|
||||
mov r0.x, c1.x
|
||||
mul r0.x, r0.x, c0.y
|
||||
cmp r0.xyz, -r0.w, c1.y, r0.x
|
||||
mov r0.w, c1.y
|
||||
mul r0, r0, t1
|
||||
mov oC0, r0
|
||||
|
||||
// approximately 7 instruction slots used
|
||||
ps_4_0
|
||||
dcl_constantbuffer CB0[1], immediateIndexed
|
||||
dcl_input_ps linear v2.xyzw
|
||||
dcl_output o0.xyzw
|
||||
dcl_temps 1
|
||||
ne r0.x, l(0.000000, 0.000000, 0.000000, 0.000000), cb0[0].x
|
||||
mul r0.y, cb0[0].y, l(0.012500)
|
||||
movc r0.xyz, r0.xxxx, r0.yyyy, l(1.000000,1.000000,1.000000,0)
|
||||
mov r0.w, l(1.000000)
|
||||
mul o0.xyzw, r0.xyzw, v2.xyzw
|
||||
ret
|
||||
// Approximately 6 instruction slots used
|
||||
#endif
|
||||
|
||||
const BYTE g_main[] =
|
||||
{
|
||||
68, 88, 66, 67, 132, 13,
|
||||
165, 35, 17, 157, 163, 217,
|
||||
158, 71, 117, 171, 46, 252,
|
||||
9, 215, 1, 0, 0, 0,
|
||||
224, 4, 0, 0, 6, 0,
|
||||
0, 0, 56, 0, 0, 0,
|
||||
4, 1, 0, 0, 244, 1,
|
||||
0, 0, 112, 2, 0, 0,
|
||||
56, 4, 0, 0, 172, 4,
|
||||
0, 0, 65, 111, 110, 57,
|
||||
196, 0, 0, 0, 196, 0,
|
||||
0, 0, 0, 2, 255, 255,
|
||||
148, 0, 0, 0, 48, 0,
|
||||
0, 0, 1, 0, 36, 0,
|
||||
0, 0, 48, 0, 0, 0,
|
||||
48, 0, 0, 0, 36, 0,
|
||||
0, 0, 48, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 2,
|
||||
255, 255, 81, 0, 0, 5,
|
||||
1, 0, 15, 160, 205, 204,
|
||||
76, 60, 0, 0, 128, 63,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 31, 0, 0, 2,
|
||||
0, 0, 0, 128, 1, 0,
|
||||
15, 176, 5, 0, 0, 3,
|
||||
0, 0, 8, 128, 0, 0,
|
||||
0, 160, 0, 0, 0, 160,
|
||||
1, 0, 0, 2, 0, 0,
|
||||
1, 128, 1, 0, 0, 160,
|
||||
5, 0, 0, 3, 0, 0,
|
||||
1, 128, 0, 0, 0, 128,
|
||||
0, 0, 85, 160, 88, 0,
|
||||
0, 4, 0, 0, 7, 128,
|
||||
0, 0, 255, 129, 1, 0,
|
||||
85, 160, 0, 0, 0, 128,
|
||||
1, 0, 0, 2, 0, 0,
|
||||
8, 128, 1, 0, 85, 160,
|
||||
5, 0, 0, 3, 0, 0,
|
||||
15, 128, 0, 0, 228, 128,
|
||||
1, 0, 228, 176, 1, 0,
|
||||
0, 2, 0, 8, 15, 128,
|
||||
0, 0, 228, 128, 255, 255,
|
||||
0, 0, 83, 72, 68, 82,
|
||||
232, 0, 0, 0, 64, 0,
|
||||
0, 0, 58, 0, 0, 0,
|
||||
89, 0, 0, 4, 70, 142,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 98, 16,
|
||||
0, 3, 242, 16, 16, 0,
|
||||
2, 0, 0, 0, 101, 0,
|
||||
0, 3, 242, 32, 16, 0,
|
||||
0, 0, 0, 0, 104, 0,
|
||||
0, 2, 1, 0, 0, 0,
|
||||
57, 0, 0, 11, 18, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
2, 64, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 10, 128, 32, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 56, 0, 0, 8,
|
||||
34, 0, 16, 0, 0, 0,
|
||||
0, 0, 26, 128, 32, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 64, 0, 0,
|
||||
205, 204, 76, 60, 55, 0,
|
||||
0, 12, 114, 0, 16, 0,
|
||||
0, 0, 0, 0, 6, 0,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
86, 5, 16, 0, 0, 0,
|
||||
0, 0, 2, 64, 0, 0,
|
||||
0, 0, 128, 63, 0, 0,
|
||||
128, 63, 0, 0, 128, 63,
|
||||
0, 0, 0, 0, 54, 0,
|
||||
0, 5, 130, 0, 16, 0,
|
||||
0, 0, 0, 0, 1, 64,
|
||||
0, 0, 0, 0, 128, 63,
|
||||
56, 0, 0, 7, 242, 32,
|
||||
16, 0, 0, 0, 0, 0,
|
||||
70, 14, 16, 0, 0, 0,
|
||||
0, 0, 70, 30, 16, 0,
|
||||
2, 0, 0, 0, 62, 0,
|
||||
0, 1, 83, 84, 65, 84,
|
||||
116, 0, 0, 0, 6, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 2, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
1, 0, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
82, 68, 69, 70, 192, 1,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
72, 0, 0, 0, 1, 0,
|
||||
0, 0, 28, 0, 0, 0,
|
||||
0, 4, 255, 255, 0, 1,
|
||||
0, 0, 149, 1, 0, 0,
|
||||
60, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 1, 0,
|
||||
0, 0, 67, 111, 110, 115,
|
||||
116, 97, 110, 116, 115, 0,
|
||||
171, 171, 60, 0, 0, 0,
|
||||
8, 0, 0, 0, 96, 0,
|
||||
0, 0, 80, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 32, 1, 0, 0,
|
||||
0, 0, 0, 0, 4, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
48, 1, 0, 0, 0, 0,
|
||||
0, 0, 64, 1, 0, 0,
|
||||
4, 0, 0, 0, 4, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
48, 1, 0, 0, 0, 0,
|
||||
0, 0, 79, 1, 0, 0,
|
||||
8, 0, 0, 0, 4, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
48, 1, 0, 0, 0, 0,
|
||||
0, 0, 94, 1, 0, 0,
|
||||
12, 0, 0, 0, 4, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
48, 1, 0, 0, 0, 0,
|
||||
0, 0, 101, 1, 0, 0,
|
||||
16, 0, 0, 0, 16, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
112, 1, 0, 0, 0, 0,
|
||||
0, 0, 128, 1, 0, 0,
|
||||
32, 0, 0, 0, 16, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
112, 1, 0, 0, 0, 0,
|
||||
0, 0, 135, 1, 0, 0,
|
||||
48, 0, 0, 0, 16, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
112, 1, 0, 0, 0, 0,
|
||||
0, 0, 142, 1, 0, 0,
|
||||
64, 0, 0, 0, 16, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
112, 1, 0, 0, 0, 0,
|
||||
0, 0, 115, 99, 82, 71,
|
||||
66, 95, 111, 117, 116, 112,
|
||||
117, 116, 0, 171, 171, 171,
|
||||
0, 0, 3, 0, 1, 0,
|
||||
1, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 83, 68,
|
||||
82, 95, 119, 104, 105, 116,
|
||||
101, 108, 101, 118, 101, 108,
|
||||
0, 72, 68, 82, 95, 119,
|
||||
104, 105, 116, 101, 108, 101,
|
||||
118, 101, 108, 0, 109, 97,
|
||||
120, 67, 76, 76, 0, 89,
|
||||
111, 102, 102, 115, 101, 116,
|
||||
0, 171, 171, 171, 1, 0,
|
||||
3, 0, 1, 0, 4, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 82, 99, 111, 101,
|
||||
102, 102, 0, 71, 99, 111,
|
||||
101, 102, 102, 0, 66, 99,
|
||||
111, 101, 102, 102, 0, 77,
|
||||
105, 99, 114, 111, 115, 111,
|
||||
102, 116, 32, 40, 82, 41,
|
||||
32, 72, 76, 83, 76, 32,
|
||||
83, 104, 97, 100, 101, 114,
|
||||
32, 67, 111, 109, 112, 105,
|
||||
108, 101, 114, 32, 49, 48,
|
||||
46, 49, 0, 171, 171, 171,
|
||||
73, 83, 71, 78, 108, 0,
|
||||
0, 0, 3, 0, 0, 0,
|
||||
8, 0, 0, 0, 80, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 3, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
15, 0, 0, 0, 92, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 3, 0,
|
||||
0, 0, 1, 0, 0, 0,
|
||||
3, 0, 0, 0, 101, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 3, 0,
|
||||
0, 0, 2, 0, 0, 0,
|
||||
15, 15, 0, 0, 83, 86,
|
||||
95, 80, 79, 83, 73, 84,
|
||||
73, 79, 78, 0, 84, 69,
|
||||
88, 67, 79, 79, 82, 68,
|
||||
0, 67, 79, 76, 79, 82,
|
||||
0, 171, 79, 83, 71, 78,
|
||||
44, 0, 0, 0, 1, 0,
|
||||
0, 0, 8, 0, 0, 0,
|
||||
32, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
3, 0, 0, 0, 0, 0,
|
||||
0, 0, 15, 0, 0, 0,
|
||||
83, 86, 95, 84, 65, 82,
|
||||
71, 69, 84, 0, 171, 171
|
||||
};
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
struct PixelShaderInput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 tex : TEXCOORD0;
|
||||
float4 color : COLOR0;
|
||||
};
|
||||
|
||||
#include "D3D11_PixelShader_Common.incl"
|
||||
|
||||
float4 main(PixelShaderInput input) : SV_TARGET
|
||||
{
|
||||
return input.color;
|
||||
return GetOutputColor(1.0) * input.color;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
struct PixelShaderInput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 tex : TEXCOORD0;
|
||||
float4 color : COLOR0;
|
||||
};
|
||||
|
||||
cbuffer Constants : register(b0)
|
||||
{
|
||||
float scRGB_output;
|
||||
float SDR_whitelevel;
|
||||
float HDR_whitelevel;
|
||||
float maxCLL;
|
||||
|
||||
float4 Yoffset;
|
||||
float4 Rcoeff;
|
||||
float4 Gcoeff;
|
||||
float4 Bcoeff;
|
||||
};
|
||||
|
||||
float3 scRGBtoNits(float3 v)
|
||||
{
|
||||
return v * 80.0;
|
||||
}
|
||||
|
||||
float3 scRGBfromNits(float3 v)
|
||||
{
|
||||
return v / 80.0;
|
||||
}
|
||||
|
||||
float sRGBtoLinear(float v)
|
||||
{
|
||||
if (v <= 0.04045) {
|
||||
v = (v / 12.92);
|
||||
} else {
|
||||
v = pow(abs(v + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
float sRGBfromLinear(float v)
|
||||
{
|
||||
if (v <= 0.0031308) {
|
||||
v = (v * 12.92);
|
||||
} else {
|
||||
v = (pow(abs(v), 1.0 / 2.4) * 1.055 - 0.055);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
float4 GetOutputColor(float4 rgba)
|
||||
{
|
||||
if (scRGB_output) {
|
||||
rgba.rgb = scRGBfromNits(rgba.rgb * SDR_whitelevel);
|
||||
}
|
||||
|
||||
return rgba;
|
||||
}
|
||||
|
||||
float4 GetOutputColorFromSRGB(float3 rgb)
|
||||
{
|
||||
float4 output;
|
||||
|
||||
if (scRGB_output) {
|
||||
output.r = sRGBtoLinear(rgb.r);
|
||||
output.g = sRGBtoLinear(rgb.g);
|
||||
output.b = sRGBtoLinear(rgb.b);
|
||||
rgb = scRGBfromNits(rgb * SDR_whitelevel);
|
||||
} else {
|
||||
output.rgb = rgb.rgb;
|
||||
}
|
||||
output.a = 1.0;
|
||||
|
||||
return output;
|
||||
}
|
||||
Executable → Regular
+515
-515
File diff suppressed because it is too large
Load Diff
@@ -2,41 +2,7 @@ Texture2D theTextureY : register(t0);
|
||||
Texture2D theTextureUV : register(t1);
|
||||
SamplerState theSampler : register(s0);
|
||||
|
||||
struct PixelShaderInput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 tex : TEXCOORD0;
|
||||
float4 color : COLOR0;
|
||||
};
|
||||
|
||||
cbuffer Constants : register(b0)
|
||||
{
|
||||
float4 Yoffset;
|
||||
float4 Rcoeff;
|
||||
float4 Gcoeff;
|
||||
float4 Bcoeff;
|
||||
|
||||
float scRGB_output;
|
||||
float SDR_whitelevel;
|
||||
float HDR_whitelevel;
|
||||
float maxCLL;
|
||||
};
|
||||
|
||||
|
||||
float3 scRGBfromNits(float3 v)
|
||||
{
|
||||
return v / 80.0;
|
||||
}
|
||||
|
||||
float sRGBfromLinear(float v)
|
||||
{
|
||||
if (v <= 0.0031308) {
|
||||
v = (v * 12.92);
|
||||
} else {
|
||||
v = (pow(abs(v), 1.0 / 2.4) * 1.055 - 0.055);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
#include "D3D11_PixelShader_Common.incl"
|
||||
|
||||
float3 PQtoNits(float3 v)
|
||||
{
|
||||
@@ -58,6 +24,7 @@ float4 main(PixelShaderInput input) : SV_TARGET
|
||||
-0.124547, 1.132895, -0.008348,
|
||||
-0.018154, -0.100597, 1.118751
|
||||
};
|
||||
float4 Output;
|
||||
|
||||
float3 yuv;
|
||||
yuv.x = theTextureY.Sample(theSampler, input.tex).r;
|
||||
@@ -84,9 +51,8 @@ float4 main(PixelShaderInput input) : SV_TARGET
|
||||
rgb.rgb = clamp(rgb.rgb, 0.0, 1.0);
|
||||
}
|
||||
|
||||
float4 Output;
|
||||
Output.rgb = rgb.rgb;
|
||||
Output.a = 1.0f;
|
||||
Output.a = 1.0;
|
||||
|
||||
return Output * input.color;
|
||||
}
|
||||
|
||||
Executable → Regular
+537
-347
File diff suppressed because it is too large
Load Diff
@@ -2,21 +2,7 @@ Texture2D theTextureY : register(t0);
|
||||
Texture2D theTextureUV : register(t1);
|
||||
SamplerState theSampler : register(s0);
|
||||
|
||||
struct PixelShaderInput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 tex : TEXCOORD0;
|
||||
float4 color : COLOR0;
|
||||
};
|
||||
|
||||
cbuffer Constants : register(b0)
|
||||
{
|
||||
float4 Yoffset;
|
||||
float4 Rcoeff;
|
||||
float4 Gcoeff;
|
||||
float4 Bcoeff;
|
||||
};
|
||||
|
||||
#include "D3D11_PixelShader_Common.incl"
|
||||
|
||||
float4 main(PixelShaderInput input) : SV_TARGET
|
||||
{
|
||||
@@ -26,11 +12,11 @@ float4 main(PixelShaderInput input) : SV_TARGET
|
||||
yuv.x = theTextureY.Sample(theSampler, input.tex).r;
|
||||
yuv.yz = theTextureUV.Sample(theSampler, input.tex).rg;
|
||||
|
||||
float3 rgb;
|
||||
yuv += Yoffset.xyz;
|
||||
Output.r = dot(yuv, Rcoeff.xyz);
|
||||
Output.g = dot(yuv, Gcoeff.xyz);
|
||||
Output.b = dot(yuv, Bcoeff.xyz);
|
||||
Output.a = 1.0f;
|
||||
rgb.r = dot(yuv, Rcoeff.xyz);
|
||||
rgb.g = dot(yuv, Gcoeff.xyz);
|
||||
rgb.b = dot(yuv, Bcoeff.xyz);
|
||||
|
||||
return Output * input.color;
|
||||
return GetOutputColorFromSRGB(rgb) * input.color;
|
||||
}
|
||||
|
||||
Executable → Regular
+540
-350
File diff suppressed because it is too large
Load Diff
@@ -2,21 +2,7 @@ Texture2D theTextureY : register(t0);
|
||||
Texture2D theTextureUV : register(t1);
|
||||
SamplerState theSampler : register(s0);
|
||||
|
||||
struct PixelShaderInput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 tex : TEXCOORD0;
|
||||
float4 color : COLOR0;
|
||||
};
|
||||
|
||||
cbuffer Constants : register(b0)
|
||||
{
|
||||
float4 Yoffset;
|
||||
float4 Rcoeff;
|
||||
float4 Gcoeff;
|
||||
float4 Bcoeff;
|
||||
};
|
||||
|
||||
#include "D3D11_PixelShader_Common.incl"
|
||||
|
||||
float4 main(PixelShaderInput input) : SV_TARGET
|
||||
{
|
||||
@@ -26,11 +12,11 @@ float4 main(PixelShaderInput input) : SV_TARGET
|
||||
yuv.x = theTextureY.Sample(theSampler, input.tex).r;
|
||||
yuv.yz = theTextureUV.Sample(theSampler, input.tex).gr;
|
||||
|
||||
float3 rgb;
|
||||
yuv += Yoffset.xyz;
|
||||
Output.r = dot(yuv, Rcoeff.xyz);
|
||||
Output.g = dot(yuv, Gcoeff.xyz);
|
||||
Output.b = dot(yuv, Bcoeff.xyz);
|
||||
Output.a = 1.0f;
|
||||
rgb.r = dot(yuv, Rcoeff.xyz);
|
||||
rgb.g = dot(yuv, Gcoeff.xyz);
|
||||
rgb.b = dot(yuv, Bcoeff.xyz);
|
||||
|
||||
return Output * input.color;
|
||||
return GetOutputColorFromSRGB(rgb) * input.color;
|
||||
}
|
||||
|
||||
Executable → Regular
+341
-198
File diff suppressed because it is too large
Load Diff
@@ -1,14 +1,9 @@
|
||||
Texture2D theTexture : register(t0);
|
||||
SamplerState theSampler : register(s0);
|
||||
|
||||
struct PixelShaderInput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 tex : TEXCOORD0;
|
||||
float4 color : COLOR0;
|
||||
};
|
||||
#include "D3D11_PixelShader_Common.incl"
|
||||
|
||||
float4 main(PixelShaderInput input) : SV_TARGET
|
||||
{
|
||||
return theTexture.Sample(theSampler, input.tex) * input.color;
|
||||
return GetOutputColor(theTexture.Sample(theSampler, input.tex)) * input.color;
|
||||
}
|
||||
|
||||
Executable → Regular
+572
-382
File diff suppressed because it is too large
Load Diff
@@ -3,21 +3,7 @@ Texture2D theTextureU : register(t1);
|
||||
Texture2D theTextureV : register(t2);
|
||||
SamplerState theSampler : register(s0);
|
||||
|
||||
struct PixelShaderInput
|
||||
{
|
||||
float4 pos : SV_POSITION;
|
||||
float2 tex : TEXCOORD0;
|
||||
float4 color : COLOR0;
|
||||
};
|
||||
|
||||
cbuffer Constants : register(b0)
|
||||
{
|
||||
float4 Yoffset;
|
||||
float4 Rcoeff;
|
||||
float4 Gcoeff;
|
||||
float4 Bcoeff;
|
||||
};
|
||||
|
||||
#include "D3D11_PixelShader_Common.incl"
|
||||
|
||||
float4 main(PixelShaderInput input) : SV_TARGET
|
||||
{
|
||||
@@ -28,11 +14,11 @@ float4 main(PixelShaderInput input) : SV_TARGET
|
||||
yuv.y = theTextureU.Sample(theSampler, input.tex).r;
|
||||
yuv.z = theTextureV.Sample(theSampler, input.tex).r;
|
||||
|
||||
float3 rgb;
|
||||
yuv += Yoffset.xyz;
|
||||
Output.r = dot(yuv, Rcoeff.xyz);
|
||||
Output.g = dot(yuv, Gcoeff.xyz);
|
||||
Output.b = dot(yuv, Bcoeff.xyz);
|
||||
Output.a = 1.0f;
|
||||
rgb.r = dot(yuv, Rcoeff.xyz);
|
||||
rgb.g = dot(yuv, Gcoeff.xyz);
|
||||
rgb.b = dot(yuv, Bcoeff.xyz);
|
||||
|
||||
return Output * input.color;
|
||||
return GetOutputColorFromSRGB(rgb) * input.color;
|
||||
}
|
||||
|
||||
Executable → Regular
+339
-339
File diff suppressed because it is too large
Load Diff
@@ -76,11 +76,11 @@ typedef struct
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float YCbCr_matrix[16];
|
||||
float scRGB_output;
|
||||
float SDR_whitelevel;
|
||||
float HDR_whitelevel;
|
||||
float maxCLL;
|
||||
float YCbCr_matrix[16];
|
||||
} PixelShaderConstants;
|
||||
|
||||
/* Per-vertex data */
|
||||
@@ -155,6 +155,11 @@ typedef struct
|
||||
D3D_FEATURE_LEVEL featureLevel;
|
||||
SDL_bool pixelSizeChanged;
|
||||
|
||||
/* HDR state */
|
||||
SDL_bool HDR_enabled;
|
||||
int SDR_whitelevel;
|
||||
int HDR_whitelevel;
|
||||
|
||||
/* Rasterizers */
|
||||
ID3D11RasterizerState *mainRasterizer;
|
||||
ID3D11RasterizerState *clippedRasterizer;
|
||||
@@ -465,6 +470,21 @@ static ID3D11BlendState *D3D11_CreateBlendState(SDL_Renderer *renderer, SDL_Blen
|
||||
return blendState;
|
||||
}
|
||||
|
||||
static void D3D11_UpdateHDRState(SDL_Renderer *renderer)
|
||||
{
|
||||
D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
|
||||
|
||||
/* Using some placeholder values here... */
|
||||
data->HDR_enabled = SDL_TRUE;
|
||||
if (renderer->output_colorspace == SDL_COLORSPACE_SCRGB && data->HDR_enabled) {
|
||||
data->SDR_whitelevel = 200.0f;
|
||||
data->HDR_whitelevel = 400.0f;
|
||||
} else {
|
||||
data->SDR_whitelevel = 80.0f;
|
||||
data->HDR_whitelevel = 80.0f;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create resources that depend on the device. */
|
||||
static HRESULT D3D11_CreateDeviceResources(SDL_Renderer *renderer)
|
||||
{
|
||||
@@ -716,6 +736,8 @@ static HRESULT D3D11_CreateDeviceResources(SDL_Renderer *renderer)
|
||||
|
||||
SDL_SetProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_D3D11_DEVICE_POINTER, data->d3dDevice);
|
||||
|
||||
D3D11_UpdateHDRState(renderer);
|
||||
|
||||
done:
|
||||
SAFE_RELEASE(d3dDevice);
|
||||
SAFE_RELEASE(d3dContext);
|
||||
@@ -2177,46 +2199,42 @@ static int D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *c
|
||||
rendererData->currentBlendState = blendState;
|
||||
}
|
||||
|
||||
if (shader_params != rendererData->currentShaderParams[shader]) {
|
||||
if (!rendererData->pixelShaderConstants[shader] ||
|
||||
shader_params != rendererData->currentShaderParams[shader]) {
|
||||
SAFE_RELEASE(rendererData->pixelShaderConstants[shader]);
|
||||
|
||||
PixelShaderConstants constants;
|
||||
if (renderer->output_colorspace == SDL_COLORSPACE_SCRGB) {
|
||||
constants.scRGB_output = 1.0f;
|
||||
} else {
|
||||
constants.scRGB_output = 0.0f;
|
||||
}
|
||||
|
||||
constants.SDR_whitelevel = (float)rendererData->SDR_whitelevel;
|
||||
constants.HDR_whitelevel = (float)rendererData->HDR_whitelevel;
|
||||
constants.maxCLL = 400.0f;
|
||||
|
||||
if (shader_params) {
|
||||
SAFE_RELEASE(rendererData->pixelShaderConstants[shader]);
|
||||
|
||||
PixelShaderConstants constants;
|
||||
SDL_memcpy(constants.YCbCr_matrix, shader_params, sizeof(constants.YCbCr_matrix));
|
||||
if (renderer->output_colorspace == SDL_COLORSPACE_SCRGB) {
|
||||
constants.scRGB_output = 1.0f;
|
||||
} else {
|
||||
constants.scRGB_output = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
/* Using some placeholder values here... */
|
||||
const SDL_bool HDR = SDL_TRUE;
|
||||
if (renderer->output_colorspace == SDL_COLORSPACE_SCRGB && HDR) {
|
||||
constants.SDR_whitelevel = 200.0f;
|
||||
constants.HDR_whitelevel = 400.0f;
|
||||
} else {
|
||||
constants.SDR_whitelevel = 80.0f;
|
||||
constants.HDR_whitelevel = 80.0f;
|
||||
}
|
||||
constants.maxCLL = 400.0f;
|
||||
D3D11_BUFFER_DESC desc;
|
||||
SDL_zero(desc);
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.ByteWidth = sizeof(constants);
|
||||
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
||||
|
||||
D3D11_BUFFER_DESC desc;
|
||||
SDL_zero(desc);
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.ByteWidth = sizeof(constants);
|
||||
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
|
||||
D3D11_SUBRESOURCE_DATA data;
|
||||
SDL_zero(data);
|
||||
data.pSysMem = &constants;
|
||||
|
||||
D3D11_SUBRESOURCE_DATA data;
|
||||
SDL_zero(data);
|
||||
data.pSysMem = &constants;
|
||||
|
||||
HRESULT result = ID3D11Device_CreateBuffer(rendererData->d3dDevice, &desc, &data, &rendererData->pixelShaderConstants[shader]);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device::CreateBuffer [create shader constants]"), result);
|
||||
return -1;
|
||||
}
|
||||
HRESULT result = ID3D11Device_CreateBuffer(rendererData->d3dDevice, &desc, &data, &rendererData->pixelShaderConstants[shader]);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device::CreateBuffer [create shader constants]"), result);
|
||||
return -1;
|
||||
}
|
||||
rendererData->currentShaderParams[shader] = shader_params;
|
||||
rendererData->currentShader = SHADER_NONE;
|
||||
}
|
||||
if (shader != rendererData->currentShader) {
|
||||
if (!rendererData->pixelShaders[shader]) {
|
||||
@@ -2371,7 +2389,13 @@ static int D3D11_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
||||
SDL_bool convert_color = SDL_RenderingLinearSpace(renderer);
|
||||
SDL_FColor color = cmd->data.color.color;
|
||||
if (convert_color) {
|
||||
float light_scale = (float)rendererData->SDR_whitelevel / 80.0f;
|
||||
|
||||
SDL_ConvertToLinear(&color);
|
||||
|
||||
color.r *= light_scale;
|
||||
color.g *= light_scale;
|
||||
color.b *= light_scale;
|
||||
}
|
||||
ID3D11DeviceContext_ClearRenderTargetView(rendererData->d3dContext, D3D11_GetCurrentRenderTargetView(renderer), &color.r);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user