Skip to content

Commit 3d0d063

Browse files
committed
shader update
1 parent db7b3ed commit 3d0d063

2 files changed

Lines changed: 88 additions & 74 deletions

File tree

src/lib/public/shaderlib.lib

8.89 KB
Binary file not shown.

src/materialsystem/stdshaders/video_yuv_ps30.fxc

Lines changed: 88 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -15,82 +15,102 @@
1515
//
1616
//------------------------------------------------------------------------------------------
1717

18-
#define SRC_BIT_DEPTH_8 0
19-
#define SRC_BIT_DEPTH_10 1
20-
#define SRC_BIT_DEPTH_12 2
21-
22-
#define AVCOL_RANGE_MPEG 0
23-
#define AVCOL_RANGE_JPEG 1
24-
25-
#define AVCOL_SPC_RGB 0 ///< order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
26-
#define AVCOL_SPC_BT709 1 ///< ITU-R BT709 / ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
27-
#define AVCOL_SPC_UNSPECIFIED 1
28-
#define AVCOL_SPC_FCC 2 ///< FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
29-
#define AVCOL_SPC_BT470BG 3 ///< ITU-R BT470BG / ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
30-
#define AVCOL_SPC_SMPTE170M 3 ///< SMPTE ST 170M / ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
31-
#define AVCOL_SPC_SMPTE240M 4 ///< derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
32-
#define AVCOL_SPC_BT2020_NCL 5 ///< ITU-R BT2020 non-constant luminance system
33-
#define AVCOL_SPC_BT2020_CL 5 ///< ITU-R BT2020 constant luminance system
34-
35-
#define AVCOL_TRC_BT709 0 ///< ITU-R BT709 / ITU-R BT1361
36-
#define AVCOL_TRC_UNSPECIFIED 0
37-
#define AVCOL_TRC_GAMMA22 1 ///< ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
38-
#define AVCOL_TRC_GAMMA28 2 ///< ITU-R BT470BG
39-
#define AVCOL_TRC_SMPTE170M 0 ///< SMPTE ST 170M / ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
40-
#define AVCOL_TRC_SMPTE240M 3 ///< SMPTE ST 240M
41-
#define AVCOL_TRC_LINEAR 4 ///< "Linear transfer characteristic"
42-
#define AVCOL_TRC_LOG100 5 ///< "Logarithmic transfer characteristic (100:1 range)"
43-
#define AVCOL_TRC_LOG_SQRT 6 ///< "Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range)"
44-
#define AVCOL_TRC_IEC61966_2_4 7 ///< IEC 61966-2-4
45-
#define AVCOL_TRC_BT1361_ECG 8 ///< ITU-R BT1361 Extended Colour Gamut
46-
#define AVCOL_TRC_IEC61966_2_1 9 ///< IEC 61966-2-1 (sRGB or sYCC)
47-
#define AVCOL_TRC_BT2020_10 0 ///< ITU-R BT2020 for 10-bit system
48-
#define AVCOL_TRC_BT2020_12 0 ///< ITU-R BT2020 for 12-bit system
49-
#define AVCOL_TRC_SMPTE2084 10 ///< SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems (PQ)
50-
#define AVCOL_TRC_SMPTE428 11 ///< SMPTE ST 428-1
51-
#define AVCOL_TRC_ARIB_STD_B67 12 ///< ARIB STD-B67, known as "Hybrid log-gamma" (HLG)
52-
53-
#define AVCOL_PRI_BT709 0 ///< ITU-R BT709 / ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
54-
#define AVCOL_PRI_UNSPECIFIED 0
55-
#define AVCOL_PRI_BT470M 1 ///< ITU-R BT470M / FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
56-
#define AVCOL_PRI_BT470BG 2 ///< ITU-R BT470BG / ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
57-
#define AVCOL_PRI_SMPTE170M 3 ///< SMPTE ST 170M / ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
58-
#define AVCOL_PRI_SMPTE240M 3 ///< SMPTE ST 240M, also called "SMPTE C" even though it uses D65
59-
#define AVCOL_PRI_FILM 4 ///< colour filters using Illuminant C
60-
#define AVCOL_PRI_BT2020 5 ///< ITU-R BT2020
61-
#define AVCOL_PRI_SMPTE428 6 ///< SMPTE ST 428-1 (CIE 1931 XYZ)
62-
#define AVCOL_PRI_SMPTE431 7 ///< SMPTE ST 431-2 (2011) / DCI P3
63-
#define AVCOL_PRI_SMPTE432 7 ///< SMPTE ST 432-1 (2010) / P3 D65 / Display P3
64-
#define AVCOL_PRI_EBU3213 8 ///< EBU Tech. 3213-E (nothing there) / one of JEDEC P22 group phosphors
18+
#define SRC_BIT_DEPTH_8 0
19+
#define SRC_BIT_DEPTH_10 1
20+
#define SRC_BIT_DEPTH_12 2
21+
22+
#define AVCOL_RANGE_MPEG 0
23+
#define AVCOL_RANGE_JPEG 1
24+
25+
#define AVCOL_SPC_RGB 0 ///< order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
26+
#define AVCOL_SPC_BT709 1 ///< ITU-R BT709 / ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
27+
#define AVCOL_SPC_UNSPECIFIED 1
28+
#define AVCOL_SPC_FCC 2 ///< FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
29+
#define AVCOL_SPC_BT470BG 3 ///< ITU-R BT470BG / ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
30+
#define AVCOL_SPC_SMPTE170M 3 ///< SMPTE ST 170M / ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
31+
#define AVCOL_SPC_SMPTE240M 4 ///< derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
32+
#define AVCOL_SPC_BT2020_NCL 5 ///< ITU-R BT2020 non-constant luminance system
33+
#define AVCOL_SPC_BT2020_CL 5 ///< ITU-R BT2020 constant luminance system
34+
35+
#define AVCOL_TRC_BT709 0 ///< ITU-R BT709 / ITU-R BT1361
36+
#define AVCOL_TRC_UNSPECIFIED 0
37+
#define AVCOL_TRC_GAMMA22 1 ///< ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
38+
#define AVCOL_TRC_GAMMA28 2 ///< ITU-R BT470BG
39+
#define AVCOL_TRC_SMPTE170M 0 ///< SMPTE ST 170M / ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
40+
#define AVCOL_TRC_SMPTE240M 3 ///< SMPTE ST 240M
41+
#define AVCOL_TRC_LINEAR 4 ///< "Linear transfer characteristic"
42+
#define AVCOL_TRC_LOG100 5 ///< "Logarithmic transfer characteristic (100:1 range)"
43+
#define AVCOL_TRC_LOG_SQRT 6 ///< "Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range)"
44+
#define AVCOL_TRC_IEC61966_2_4 7 ///< IEC 61966-2-4
45+
#define AVCOL_TRC_BT1361_ECG 8 ///< ITU-R BT1361 Extended Colour Gamut
46+
#define AVCOL_TRC_IEC61966_2_1 9 ///< IEC 61966-2-1 (sRGB or sYCC)
47+
#define AVCOL_TRC_BT2020_10 0 ///< ITU-R BT2020 for 10-bit system
48+
#define AVCOL_TRC_BT2020_12 0 ///< ITU-R BT2020 for 12-bit system
49+
#define AVCOL_TRC_SMPTE2084 10 ///< SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems (PQ)
50+
#define AVCOL_TRC_SMPTE428 11 ///< SMPTE ST 428-1
51+
#define AVCOL_TRC_ARIB_STD_B67 12 ///< ARIB STD-B67, known as "Hybrid log-gamma" (HLG)
52+
53+
#define AVCOL_PRI_BT709 0 ///< ITU-R BT709 / ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
54+
#define AVCOL_PRI_UNSPECIFIED 0
55+
#define AVCOL_PRI_BT470M 1 ///< ITU-R BT470M / FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
56+
#define AVCOL_PRI_BT470BG 2 ///< ITU-R BT470BG / ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
57+
#define AVCOL_PRI_SMPTE170M 3 ///< SMPTE ST 170M / ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
58+
#define AVCOL_PRI_SMPTE240M 3 ///< SMPTE ST 240M, also called "SMPTE C" even though it uses D65
59+
#define AVCOL_PRI_FILM 4 ///< colour filters using Illuminant C
60+
#define AVCOL_PRI_BT2020 5 ///< ITU-R BT2020
61+
#define AVCOL_PRI_SMPTE428 6 ///< SMPTE ST 428-1 (CIE 1931 XYZ)
62+
#define AVCOL_PRI_SMPTE431 7 ///< SMPTE ST 431-2 (2011) / DCI P3
63+
#define AVCOL_PRI_SMPTE432 7 ///< SMPTE ST 432-1 (2010) / P3 D65 / Display P3
64+
#define AVCOL_PRI_EBU3213 8 ///< EBU Tech. 3213-E (nothing there) / one of JEDEC P22 group phosphors
6565

6666
//------------------------------------------------------------------------------------------
6767
// Macros based on static parameters
6868
//------------------------------------------------------------------------------------------
6969

7070
#if SRC_BIT_DEPTH == SRC_BIT_DEPTH_8
71-
#define MAX_VAL 255.0f
72-
static const float SCALE = 255.0f / MAX_VAL;
73-
#define MIN_YUV 16.0f
74-
#define MAX_Y 235.0f
75-
#define MAX_UV 240.0f
71+
//#define MAX_VAL 255.0f
72+
//#define MIN_YUV 16.0f
73+
//#define MAX_Y 235.0f
74+
//#define MAX_UV 240.0f
75+
//static const float SCALE = 255.0f / MAX_VAL;
76+
77+
static const float SCALE = 1.0f; ///< (255.0f / MAX_VAL)
78+
#define YUV_OFFSET 0.06274509803921568627450980392157f ///< (MIN_YUV / MAX_VAL)
79+
#define Y_SCALE 1.1643835616438356164383561643836f ///< 1.0f / ((MAX_Y - MIN_YUV) / MAX_VAL)
80+
#define UV_SCALE 1.1383928571428571428571428571429f ///< 1.0f / ((MAX_UV - MIN_YUV) / MAX_VAL)
81+
7682
#elif SRC_BIT_DEPTH == SRC_BIT_DEPTH_10
77-
#define MAX_VAL 1023.0f
78-
static const float SCALE = 255.0f / MAX_VAL;
79-
#define MIN_YUV 64.0f
80-
#define MAX_Y 940.0f
81-
#define MAX_UV 960.0f
83+
//#define MAX_VAL 1023.0f
84+
//#define MIN_YUV 64.0f
85+
//#define MAX_Y 940.0f
86+
//#define MAX_UV 960.0f
87+
//static const float SCALE = 255.0f / MAX_VAL;
88+
89+
static const float SCALE = 0.24926686217008797653958944281525f;///< (255.0f / MAX_VAL)
90+
#define YUV_OFFSET 0.06256109481915933528836754643206f ///< (MIN_YUV / MAX_VAL)
91+
#define Y_SCALE 1.1678082191780821917808219178082f ///< 1.0f / ((MAX_Y - MIN_YUV) / MAX_VAL)
92+
#define UV_SCALE 1.1417410714285714285714285714286f ///< 1.0f / ((MAX_UV - MIN_YUV) / MAX_VAL)
93+
8294
#else // #elif SRC_BIT_DEPTH == SRC_BIT_DEPTH_12
83-
#define MAX_VAL 4095.0f
84-
static const float SCALE = 255.0f / MAX_VAL;
85-
#define MIN_YUV 256.0f
86-
#define MAX_Y 3760.0f
87-
#define MAX_UV 3840.0f
95+
//#define MAX_VAL 4095.0f
96+
//#define MIN_YUV 256.0f
97+
//#define MAX_Y 3760.0f
98+
//#define MAX_UV 3840.0f
99+
//static const float SCALE = 255.0f / MAX_VAL;
100+
101+
static const float SCALE = 0.06227106227106227106227106227106f;///< (255.0f / MAX_VAL)
102+
#define YUV_OFFSET 0.06251526251526251526251526251526f ///< (MIN_YUV / MAX_VAL)
103+
#define Y_SCALE 1.1686643835616438356164383561644f ///< 1.0f / ((MAX_Y - MIN_YUV) / MAX_VAL)
104+
#define UV_SCALE 1.142578125f ///< 1.0f / ((MAX_UV - MIN_YUV) / MAX_VAL)
88105
#endif
89106

90107
#if AVCOL_RANGE != AVCOL_RANGE_JPEG
91-
static const float YUV_OFFSET = (MIN_YUV / MAX_VAL);
92-
static const float Y_SCALE = 1 / ((MAX_Y - MIN_YUV) / MAX_VAL);
93-
static const float UV_SCALE = 1 / ((MAX_UV - MIN_YUV) / MAX_VAL);
108+
static const float3 YUV_SCALE_VEC = float3(Y_SCALE, UV_SCALE, UV_SCALE);
109+
static const float3 YUV_OFFSET_VEC = float3(
110+
-YUV_OFFSET * Y_SCALE,
111+
-YUV_OFFSET * UV_SCALE - 0.5f,
112+
-YUV_OFFSET * UV_SCALE - 0.5f
113+
);
94114
#endif
95115

96116
static const float3x3 MATRIX_YUV_RGB = float3x3(
@@ -231,19 +251,13 @@ inline float3 getSampleYUV( float2 uv )
231251
#endif
232252

233253
//#if AVCOL_RANGE != AVCOL_RANGE_JPEG
234-
// yuv = (yuv - YUV_OFFSET) * float3(Y_SCALE, UV_SCALE, UV_SCALE);
254+
// yuv = (yuv - YUV_OFFSET_VEC) * YUV_SCALE_VEC;
235255
//#endif
236256
// yuv.yz -= 0.5;
237257
#if AVCOL_RANGE != AVCOL_RANGE_JPEG
238-
// Optim: (yuv-O)*S = yuv*S - O*S (with chroma shift)
239-
const float3 precomputed_const = float3(
240-
-YUV_OFFSET * Y_SCALE,
241-
-YUV_OFFSET * UV_SCALE - 0.5,
242-
-YUV_OFFSET * UV_SCALE - 0.5
243-
);
244-
yuv = mad(yuv, float3(Y_SCALE, UV_SCALE, UV_SCALE), precomputed_const);
258+
yuv = mad( yuv, YUV_SCALE_VEC, YUV_OFFSET_VEC );
245259
#else
246-
yuv.yz -= 0.5;
260+
yuv.yz -= 0.5f;
247261
#endif
248262

249263
return yuv;

0 commit comments

Comments
 (0)