format_conversion.effect 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  1. /******************************************************************************
  2. Copyright (C) 2014 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "color.effect"
  15. uniform float width;
  16. uniform float height;
  17. uniform float width_i;
  18. uniform float height_i;
  19. uniform float width_d2;
  20. uniform float height_d2;
  21. uniform float width_x2_i;
  22. uniform float maximum_over_sdr_white_nits;
  23. uniform float sdr_white_nits_over_maximum;
  24. uniform float4 color_vec0;
  25. uniform float4 color_vec1;
  26. uniform float4 color_vec2;
  27. uniform float3 color_range_min = {0.0, 0.0, 0.0};
  28. uniform float3 color_range_max = {1.0, 1.0, 1.0};
  29. uniform texture2d image;
  30. uniform texture2d image1;
  31. uniform texture2d image2;
  32. uniform texture2d image3;
  33. sampler_state def_sampler {
  34. Filter = Linear;
  35. AddressU = Clamp;
  36. AddressV = Clamp;
  37. };
  38. struct FragPos {
  39. float4 pos : POSITION;
  40. };
  41. struct VertTexPos {
  42. float2 uv : TEXCOORD0;
  43. float4 pos : POSITION;
  44. };
  45. struct VertPosWide {
  46. float3 pos_wide : TEXCOORD0;
  47. float4 pos : POSITION;
  48. };
  49. struct VertTexPosWide {
  50. float3 uuv : TEXCOORD0;
  51. float4 pos : POSITION;
  52. };
  53. struct VertTexPosWideWide {
  54. float4 uuvv : TEXCOORD0;
  55. float4 pos : POSITION;
  56. };
  57. struct FragTex {
  58. float2 uv : TEXCOORD0;
  59. };
  60. struct FragPosWide {
  61. float3 pos_wide : TEXCOORD0;
  62. };
  63. struct FragTexWide {
  64. float3 uuv : TEXCOORD0;
  65. };
  66. struct FragTexWideWide {
  67. float4 uuvv : TEXCOORD0;
  68. };
  69. FragPos VSPos(uint id : VERTEXID)
  70. {
  71. float idHigh = float(id >> 1);
  72. float idLow = float(id & uint(1));
  73. float x = idHigh * 4.0 - 1.0;
  74. float y = idLow * 4.0 - 1.0;
  75. FragPos vert_out;
  76. vert_out.pos = float4(x, y, 0.0, 1.0);
  77. return vert_out;
  78. }
  79. VertTexPosWide VSTexPos_Left(uint id : VERTEXID)
  80. {
  81. float idHigh = float(id >> 1);
  82. float idLow = float(id & uint(1));
  83. float x = idHigh * 4.0 - 1.0;
  84. float y = idLow * 4.0 - 1.0;
  85. float u_right = idHigh * 2.0;
  86. float u_left = u_right - width_i;
  87. float v = obs_glsl_compile ? (idLow * 2.0) : (1.0 - idLow * 2.0);
  88. VertTexPosWide vert_out;
  89. vert_out.uuv = float3(u_left, u_right, v);
  90. vert_out.pos = float4(x, y, 0.0, 1.0);
  91. return vert_out;
  92. }
  93. VertTexPosWideWide VSTexPos_TopLeft(uint id : VERTEXID)
  94. {
  95. float idHigh = float(id >> 1);
  96. float idLow = float(id & uint(1));
  97. float x = idHigh * 4.0 - 1.0;
  98. float y = idLow * 4.0 - 1.0;
  99. float u_right = idHigh * 2.0;
  100. float u_left = u_right - width_i;
  101. float v_bottom;
  102. float v_top;
  103. if (obs_glsl_compile) {
  104. v_bottom = idLow * 2.0;
  105. v_top = v_bottom + height_i;
  106. } else {
  107. v_bottom = 1.0 - idLow * 2.0;
  108. v_top = v_bottom - height_i;
  109. }
  110. VertTexPosWideWide vert_out;
  111. vert_out.uuvv = float4(u_left, u_right, v_top, v_bottom);
  112. vert_out.pos = float4(x, y, 0.0, 1.0);
  113. return vert_out;
  114. }
  115. VertTexPos VSTexPosHalf_Reverse(uint id : VERTEXID)
  116. {
  117. float idHigh = float(id >> 1);
  118. float idLow = float(id & uint(1));
  119. float x = idHigh * 4.0 - 1.0;
  120. float y = idLow * 4.0 - 1.0;
  121. float u = idHigh * 2.0;
  122. float v = obs_glsl_compile ? (idLow * 2.0) : (1.0 - idLow * 2.0);
  123. VertTexPos vert_out;
  124. vert_out.uv = float2(width_d2 * u, height * v);
  125. vert_out.pos = float4(x, y, 0.0, 1.0);
  126. return vert_out;
  127. }
  128. VertTexPos VSTexPosHalfHalf_Reverse(uint id : VERTEXID)
  129. {
  130. float idHigh = float(id >> 1);
  131. float idLow = float(id & uint(1));
  132. float x = idHigh * 4.0 - 1.0;
  133. float y = idLow * 4.0 - 1.0;
  134. float u = idHigh * 2.0;
  135. float v = obs_glsl_compile ? (idLow * 2.0) : (1.0 - idLow * 2.0);
  136. VertTexPos vert_out;
  137. vert_out.uv = float2(width_d2 * u, height_d2 * v);
  138. vert_out.pos = float4(x, y, 0.0, 1.0);
  139. return vert_out;
  140. }
  141. VertPosWide VSPosWide_Reverse(uint id : VERTEXID)
  142. {
  143. float idHigh = float(id >> 1);
  144. float idLow = float(id & uint(1));
  145. float x = idHigh * 4.0 - 1.0;
  146. float y = idLow * 4.0 - 1.0;
  147. float u = idHigh * 2.0;
  148. float v = obs_glsl_compile ? (idLow * 2.0) : (1.0 - idLow * 2.0);
  149. VertPosWide vert_out;
  150. vert_out.pos_wide = float3(float2(width, width_d2) * u, height * v);
  151. vert_out.pos = float4(x, y, 0.0, 1.0);
  152. return vert_out;
  153. }
  154. float PS_Y(FragPos frag_in) : TARGET
  155. {
  156. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  157. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  158. return y;
  159. }
  160. float PS_PQ_Y_709_2020(FragPos frag_in) : TARGET
  161. {
  162. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb * sdr_white_nits_over_maximum;
  163. rgb = rec709_to_rec2020(rgb);
  164. rgb = linear_to_st2084(rgb);
  165. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  166. y = (65472. / 65535.) * y + 0.00048828125; // set up truncation to 10 bits
  167. return y;
  168. }
  169. float PS_HLG_Y_709_2020(FragPos frag_in) : TARGET
  170. {
  171. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb * sdr_white_nits_over_maximum;
  172. rgb = rec709_to_rec2020(rgb);
  173. rgb = linear_to_hlg(rgb);
  174. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  175. y = (65472. / 65535.) * y + 0.00048828125; // set up truncation to 10 bits
  176. return y;
  177. }
  178. float PS_I010_PQ_Y_709_2020(FragPos frag_in) : TARGET
  179. {
  180. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb * sdr_white_nits_over_maximum;
  181. rgb = rec709_to_rec2020(rgb);
  182. rgb = linear_to_st2084(rgb);
  183. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  184. return y * (1023. / 65535.);
  185. }
  186. float PS_I010_HLG_Y_709_2020(FragPos frag_in) : TARGET
  187. {
  188. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb * sdr_white_nits_over_maximum;
  189. rgb = rec709_to_rec2020(rgb);
  190. rgb = linear_to_hlg(rgb);
  191. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  192. return y * (1023. / 65535.);
  193. }
  194. float2 PS_UV_Wide(FragTexWide frag_in) : TARGET
  195. {
  196. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  197. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  198. float3 rgb = (rgb_left + rgb_right) * 0.5;
  199. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  200. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  201. return float2(u, v);
  202. }
  203. float2 PS_PQ_UV_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  204. {
  205. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  206. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  207. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  208. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  209. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  210. rgb = rec709_to_rec2020(rgb);
  211. rgb = linear_to_st2084(rgb);
  212. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  213. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  214. float2 uv = float2(u, v);
  215. uv = (65472. / 65535.) * uv + 0.00048828125; // set up truncation to 10 bits
  216. return uv;
  217. }
  218. float2 PS_HLG_UV_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  219. {
  220. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  221. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  222. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  223. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  224. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  225. rgb = rec709_to_rec2020(rgb);
  226. rgb = linear_to_hlg(rgb);
  227. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  228. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  229. float2 uv = float2(u, v);
  230. uv = (65472. / 65535.) * uv + 0.00048828125; // set up truncation to 10 bits
  231. return uv;
  232. }
  233. float PS_U(FragPos frag_in) : TARGET
  234. {
  235. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  236. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  237. return u;
  238. }
  239. float PS_V(FragPos frag_in) : TARGET
  240. {
  241. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  242. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  243. return v;
  244. }
  245. float PS_U_Wide(FragTexWide frag_in) : TARGET
  246. {
  247. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  248. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  249. float3 rgb = (rgb_left + rgb_right) * 0.5;
  250. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  251. return u;
  252. }
  253. float PS_V_Wide(FragTexWide frag_in) : TARGET
  254. {
  255. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  256. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  257. float3 rgb = (rgb_left + rgb_right) * 0.5;
  258. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  259. return v;
  260. }
  261. float PS_I010_PQ_U_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  262. {
  263. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  264. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  265. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  266. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  267. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  268. rgb = rec709_to_rec2020(rgb);
  269. rgb = linear_to_st2084(rgb);
  270. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  271. return u * (1023. / 65535.);
  272. }
  273. float PS_I010_HLG_U_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  274. {
  275. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  276. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  277. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  278. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  279. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  280. rgb = rec709_to_rec2020(rgb);
  281. rgb = linear_to_hlg(rgb);
  282. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  283. return u * (1023. / 65535.);
  284. }
  285. float PS_I010_PQ_V_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  286. {
  287. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  288. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  289. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  290. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  291. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  292. rgb = rec709_to_rec2020(rgb);
  293. rgb = linear_to_st2084(rgb);
  294. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  295. return v * (1023. / 65535.);
  296. }
  297. float PS_I010_HLG_V_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  298. {
  299. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  300. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  301. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  302. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  303. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  304. rgb = rec709_to_rec2020(rgb);
  305. rgb = linear_to_hlg(rgb);
  306. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  307. return v * (1023. / 65535.);
  308. }
  309. float3 YUV_to_RGB(float3 yuv)
  310. {
  311. yuv = clamp(yuv, color_range_min, color_range_max);
  312. float r = dot(color_vec0.xyz, yuv) + color_vec0.w;
  313. float g = dot(color_vec1.xyz, yuv) + color_vec1.w;
  314. float b = dot(color_vec2.xyz, yuv) + color_vec2.w;
  315. return float3(r, g, b);
  316. }
  317. float3 PSUYVY_Reverse(FragTex frag_in) : TARGET
  318. {
  319. float4 y2uv = image.Load(int3(frag_in.uv.xy, 0));
  320. float2 y01 = y2uv.yw;
  321. float2 cbcr = y2uv.zx;
  322. float leftover = frac(frag_in.uv.x);
  323. float y = (leftover < 0.5) ? y01.x : y01.y;
  324. float3 yuv = float3(y, cbcr);
  325. float3 rgb = YUV_to_RGB(yuv);
  326. return rgb;
  327. }
  328. float3 PSYUY2_Reverse(FragTex frag_in) : TARGET
  329. {
  330. float4 y2uv = image.Load(int3(frag_in.uv.xy, 0));
  331. float2 y01 = y2uv.zx;
  332. float2 cbcr = y2uv.yw;
  333. float leftover = frac(frag_in.uv.x);
  334. float y = (leftover < 0.5) ? y01.x : y01.y;
  335. float3 yuv = float3(y, cbcr);
  336. float3 rgb = YUV_to_RGB(yuv);
  337. return rgb;
  338. }
  339. float3 PSYVYU_Reverse(FragTex frag_in) : TARGET
  340. {
  341. float4 y2uv = image.Load(int3(frag_in.uv.xy, 0));
  342. float2 y01 = y2uv.zx;
  343. float2 cbcr = y2uv.wy;
  344. float leftover = frac(frag_in.uv.x);
  345. float y = (leftover < 0.5) ? y01.x : y01.y;
  346. float3 yuv = float3(y, cbcr);
  347. float3 rgb = YUV_to_RGB(yuv);
  348. return rgb;
  349. }
  350. float3 PSPlanar420_Reverse(VertTexPos frag_in) : TARGET
  351. {
  352. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  353. int3 xy0_chroma = int3(frag_in.uv, 0);
  354. float cb = image1.Load(xy0_chroma).x;
  355. float cr = image2.Load(xy0_chroma).x;
  356. float3 yuv = float3(y, cb, cr);
  357. float3 rgb = YUV_to_RGB(yuv);
  358. return rgb;
  359. }
  360. float4 PSPlanar420A_Reverse(VertTexPos frag_in) : TARGET
  361. {
  362. int3 xy0_luma = int3(frag_in.pos.xy, 0);
  363. float y = image.Load(xy0_luma).x;
  364. int3 xy0_chroma = int3(frag_in.uv, 0);
  365. float cb = image1.Load(xy0_chroma).x;
  366. float cr = image2.Load(xy0_chroma).x;
  367. float alpha = image3.Load(xy0_luma).x;
  368. float3 yuv = float3(y, cb, cr);
  369. float4 rgba = float4(YUV_to_RGB(yuv), alpha);
  370. return rgba;
  371. }
  372. float3 PSPlanar422_Reverse(FragPosWide frag_in) : TARGET
  373. {
  374. float y = image.Load(int3(frag_in.pos_wide.xz, 0)).x;
  375. int3 xy0_chroma = int3(frag_in.pos_wide.yz, 0);
  376. float cb = image1.Load(xy0_chroma).x;
  377. float cr = image2.Load(xy0_chroma).x;
  378. float3 yuv = float3(y, cb, cr);
  379. float3 rgb = YUV_to_RGB(yuv);
  380. return rgb;
  381. }
  382. float4 PSPlanar422A_Reverse(FragPosWide frag_in) : TARGET
  383. {
  384. int3 xy0_luma = int3(frag_in.pos_wide.xz, 0);
  385. float y = image.Load(xy0_luma).x;
  386. int3 xy0_chroma = int3(frag_in.pos_wide.yz, 0);
  387. float cb = image1.Load(xy0_chroma).x;
  388. float cr = image2.Load(xy0_chroma).x;
  389. float alpha = image3.Load(xy0_luma).x;
  390. float3 yuv = float3(y, cb, cr);
  391. float4 rgba = float4(YUV_to_RGB(yuv), alpha);
  392. return rgba;
  393. }
  394. float3 PSPlanar444_Reverse(FragPos frag_in) : TARGET
  395. {
  396. int3 xy0 = int3(frag_in.pos.xy, 0);
  397. float y = image.Load(xy0).x;
  398. float cb = image1.Load(xy0).x;
  399. float cr = image2.Load(xy0).x;
  400. float3 yuv = float3(y, cb, cr);
  401. float3 rgb = YUV_to_RGB(yuv);
  402. return rgb;
  403. }
  404. float4 PSPlanar444A_Reverse(FragPos frag_in) : TARGET
  405. {
  406. int3 xy0 = int3(frag_in.pos.xy, 0);
  407. float y = image.Load(xy0).x;
  408. float cb = image1.Load(xy0).x;
  409. float cr = image2.Load(xy0).x;
  410. float alpha = image3.Load(xy0).x;
  411. float3 yuv = float3(y, cb, cr);
  412. float4 rgba = float4(YUV_to_RGB(yuv), alpha);
  413. return rgba;
  414. }
  415. float4 PSAYUV_Reverse(FragPos frag_in) : TARGET
  416. {
  417. float4 yuva = image.Load(int3(frag_in.pos.xy, 0));
  418. float4 rgba = float4(YUV_to_RGB(yuva.xyz), yuva.a);
  419. return rgba;
  420. }
  421. float3 PSNV12_Reverse(VertTexPos frag_in) : TARGET
  422. {
  423. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  424. float2 cbcr = image1.Load(int3(frag_in.uv, 0)).xy;
  425. float3 yuv = float3(y, cbcr);
  426. float3 rgb = YUV_to_RGB(yuv);
  427. return rgb;
  428. }
  429. float4 PSI010_PQ_2020_709_Reverse(VertTexPos frag_in) : TARGET
  430. {
  431. float ratio = 65535. / 1023.;
  432. float y = image.Load(int3(frag_in.pos.xy, 0)).x * ratio;
  433. int3 xy0_chroma = int3(frag_in.uv, 0);
  434. float cb = image1.Load(xy0_chroma).x * ratio;
  435. float cr = image2.Load(xy0_chroma).x * ratio;
  436. float3 yuv = float3(y, cb, cr);
  437. float3 pq = YUV_to_RGB(yuv);
  438. float3 hdr2020 = st2084_to_linear(pq) * maximum_over_sdr_white_nits;
  439. float3 rgb = rec2020_to_rec709(hdr2020);
  440. return float4(rgb, 1.0);
  441. }
  442. float4 PSI010_HLG_2020_709_Reverse(VertTexPos frag_in) : TARGET
  443. {
  444. float ratio = 65535. / 1023.;
  445. float y = image.Load(int3(frag_in.pos.xy, 0)).x * ratio;
  446. int3 xy0_chroma = int3(frag_in.uv, 0);
  447. float cb = image1.Load(xy0_chroma).x * ratio;
  448. float cr = image2.Load(xy0_chroma).x * ratio;
  449. float3 yuv = float3(y, cb, cr);
  450. float3 hlg = YUV_to_RGB(yuv);
  451. float3 hdr2020 = hlg_to_linear(hlg) * maximum_over_sdr_white_nits;
  452. float3 rgb = rec2020_to_rec709(hdr2020);
  453. return float4(rgb, 1.0);
  454. }
  455. float4 PSP010_PQ_2020_709_Reverse(VertTexPos frag_in) : TARGET
  456. {
  457. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  458. float2 cbcr = image1.Load(int3(frag_in.uv, 0)).xy;
  459. float3 yuv = float3(y, cbcr);
  460. float3 pq = YUV_to_RGB(yuv);
  461. float3 hdr2020 = st2084_to_linear(pq) * maximum_over_sdr_white_nits;
  462. float3 rgb = rec2020_to_rec709(hdr2020);
  463. return float4(rgb, 1.0);
  464. }
  465. float4 PSP010_HLG_2020_709_Reverse(VertTexPos frag_in) : TARGET
  466. {
  467. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  468. float2 cbcr = image1.Load(int3(frag_in.uv, 0)).xy;
  469. float3 yuv = float3(y, cbcr);
  470. float3 hlg = YUV_to_RGB(yuv);
  471. float3 hdr2020 = hlg_to_linear(hlg) * maximum_over_sdr_white_nits;
  472. float3 rgb = rec2020_to_rec709(hdr2020);
  473. return float4(rgb, 1.0);
  474. }
  475. float3 PSY800_Limited(FragPos frag_in) : TARGET
  476. {
  477. float limited = image.Load(int3(frag_in.pos.xy, 0)).x;
  478. float full = (255.0 / 219.0) * limited - (16.0 / 219.0);
  479. return float3(full, full, full);
  480. }
  481. float3 PSY800_Full(FragPos frag_in) : TARGET
  482. {
  483. float3 full = image.Load(int3(frag_in.pos.xy, 0)).xxx;
  484. return full;
  485. }
  486. float4 PSRGB_Limited(FragPos frag_in) : TARGET
  487. {
  488. float4 rgba = image.Load(int3(frag_in.pos.xy, 0));
  489. rgba.rgb = (255.0 / 219.0) * rgba.rgb - (16.0 / 219.0);
  490. return rgba;
  491. }
  492. float3 PSBGR3_Limited(FragPos frag_in) : TARGET
  493. {
  494. float x = frag_in.pos.x * 3.0;
  495. float y = frag_in.pos.y;
  496. float b = image.Load(int3(x - 1.0, y, 0)).x;
  497. float g = image.Load(int3(x, y, 0)).x;
  498. float r = image.Load(int3(x + 1.0, y, 0)).x;
  499. float3 rgb = float3(r, g, b);
  500. rgb = (255.0 / 219.0) * rgb - (16.0 / 219.0);
  501. return rgb;
  502. }
  503. float3 PSBGR3_Full(FragPos frag_in) : TARGET
  504. {
  505. float x = frag_in.pos.x * 3.0;
  506. float y = frag_in.pos.y;
  507. float b = image.Load(int3(x - 1.0, y, 0)).x;
  508. float g = image.Load(int3(x, y, 0)).x;
  509. float r = image.Load(int3(x + 1.0, y, 0)).x;
  510. float3 rgb = float3(r, g, b);
  511. return rgb;
  512. }
  513. technique Planar_Y
  514. {
  515. pass
  516. {
  517. vertex_shader = VSPos(id);
  518. pixel_shader = PS_Y(frag_in);
  519. }
  520. }
  521. technique Planar_U
  522. {
  523. pass
  524. {
  525. vertex_shader = VSPos(id);
  526. pixel_shader = PS_U(frag_in);
  527. }
  528. }
  529. technique Planar_V
  530. {
  531. pass
  532. {
  533. vertex_shader = VSPos(id);
  534. pixel_shader = PS_V(frag_in);
  535. }
  536. }
  537. technique Planar_U_Left
  538. {
  539. pass
  540. {
  541. vertex_shader = VSTexPos_Left(id);
  542. pixel_shader = PS_U_Wide(frag_in);
  543. }
  544. }
  545. technique Planar_V_Left
  546. {
  547. pass
  548. {
  549. vertex_shader = VSTexPos_Left(id);
  550. pixel_shader = PS_V_Wide(frag_in);
  551. }
  552. }
  553. technique NV12_Y
  554. {
  555. pass
  556. {
  557. vertex_shader = VSPos(id);
  558. pixel_shader = PS_Y(frag_in);
  559. }
  560. }
  561. technique NV12_UV
  562. {
  563. pass
  564. {
  565. vertex_shader = VSTexPos_Left(id);
  566. pixel_shader = PS_UV_Wide(frag_in);
  567. }
  568. }
  569. technique I010_PQ_Y
  570. {
  571. pass
  572. {
  573. vertex_shader = VSPos(id);
  574. pixel_shader = PS_I010_PQ_Y_709_2020(frag_in);
  575. }
  576. }
  577. technique I010_HLG_Y
  578. {
  579. pass
  580. {
  581. vertex_shader = VSPos(id);
  582. pixel_shader = PS_I010_HLG_Y_709_2020(frag_in);
  583. }
  584. }
  585. technique I010_PQ_U
  586. {
  587. pass
  588. {
  589. vertex_shader = VSTexPos_TopLeft(id);
  590. pixel_shader = PS_I010_PQ_U_709_2020_WideWide(frag_in);
  591. }
  592. }
  593. technique I010_HLG_U
  594. {
  595. pass
  596. {
  597. vertex_shader = VSTexPos_TopLeft(id);
  598. pixel_shader = PS_I010_HLG_U_709_2020_WideWide(frag_in);
  599. }
  600. }
  601. technique I010_PQ_V
  602. {
  603. pass
  604. {
  605. vertex_shader = VSTexPos_TopLeft(id);
  606. pixel_shader = PS_I010_PQ_V_709_2020_WideWide(frag_in);
  607. }
  608. }
  609. technique I010_HLG_V
  610. {
  611. pass
  612. {
  613. vertex_shader = VSTexPos_TopLeft(id);
  614. pixel_shader = PS_I010_HLG_V_709_2020_WideWide(frag_in);
  615. }
  616. }
  617. technique P010_PQ_Y
  618. {
  619. pass
  620. {
  621. vertex_shader = VSPos(id);
  622. pixel_shader = PS_PQ_Y_709_2020(frag_in);
  623. }
  624. }
  625. technique P010_HLG_Y
  626. {
  627. pass
  628. {
  629. vertex_shader = VSPos(id);
  630. pixel_shader = PS_HLG_Y_709_2020(frag_in);
  631. }
  632. }
  633. technique P010_PQ_UV
  634. {
  635. pass
  636. {
  637. vertex_shader = VSTexPos_TopLeft(id);
  638. pixel_shader = PS_PQ_UV_709_2020_WideWide(frag_in);
  639. }
  640. }
  641. technique P010_HLG_UV
  642. {
  643. pass
  644. {
  645. vertex_shader = VSTexPos_TopLeft(id);
  646. pixel_shader = PS_HLG_UV_709_2020_WideWide(frag_in);
  647. }
  648. }
  649. technique UYVY_Reverse
  650. {
  651. pass
  652. {
  653. vertex_shader = VSTexPosHalf_Reverse(id);
  654. pixel_shader = PSUYVY_Reverse(frag_in);
  655. }
  656. }
  657. technique YUY2_Reverse
  658. {
  659. pass
  660. {
  661. vertex_shader = VSTexPosHalf_Reverse(id);
  662. pixel_shader = PSYUY2_Reverse(frag_in);
  663. }
  664. }
  665. technique YVYU_Reverse
  666. {
  667. pass
  668. {
  669. vertex_shader = VSTexPosHalf_Reverse(id);
  670. pixel_shader = PSYVYU_Reverse(frag_in);
  671. }
  672. }
  673. technique I420_Reverse
  674. {
  675. pass
  676. {
  677. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  678. pixel_shader = PSPlanar420_Reverse(frag_in);
  679. }
  680. }
  681. technique I40A_Reverse
  682. {
  683. pass
  684. {
  685. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  686. pixel_shader = PSPlanar420A_Reverse(frag_in);
  687. }
  688. }
  689. technique I422_Reverse
  690. {
  691. pass
  692. {
  693. vertex_shader = VSPosWide_Reverse(id);
  694. pixel_shader = PSPlanar422_Reverse(frag_in);
  695. }
  696. }
  697. technique I42A_Reverse
  698. {
  699. pass
  700. {
  701. vertex_shader = VSPosWide_Reverse(id);
  702. pixel_shader = PSPlanar422A_Reverse(frag_in);
  703. }
  704. }
  705. technique I444_Reverse
  706. {
  707. pass
  708. {
  709. vertex_shader = VSPos(id);
  710. pixel_shader = PSPlanar444_Reverse(frag_in);
  711. }
  712. }
  713. technique YUVA_Reverse
  714. {
  715. pass
  716. {
  717. vertex_shader = VSPos(id);
  718. pixel_shader = PSPlanar444A_Reverse(frag_in);
  719. }
  720. }
  721. technique AYUV_Reverse
  722. {
  723. pass
  724. {
  725. vertex_shader = VSPos(id);
  726. pixel_shader = PSAYUV_Reverse(frag_in);
  727. }
  728. }
  729. technique NV12_Reverse
  730. {
  731. pass
  732. {
  733. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  734. pixel_shader = PSNV12_Reverse(frag_in);
  735. }
  736. }
  737. technique I010_PQ_2020_709_Reverse
  738. {
  739. pass
  740. {
  741. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  742. pixel_shader = PSI010_PQ_2020_709_Reverse(frag_in);
  743. }
  744. }
  745. technique I010_HLG_2020_709_Reverse
  746. {
  747. pass
  748. {
  749. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  750. pixel_shader = PSI010_HLG_2020_709_Reverse(frag_in);
  751. }
  752. }
  753. technique P010_PQ_2020_709_Reverse
  754. {
  755. pass
  756. {
  757. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  758. pixel_shader = PSP010_PQ_2020_709_Reverse(frag_in);
  759. }
  760. }
  761. technique P010_HLG_2020_709_Reverse
  762. {
  763. pass
  764. {
  765. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  766. pixel_shader = PSP010_HLG_2020_709_Reverse(frag_in);
  767. }
  768. }
  769. technique Y800_Limited
  770. {
  771. pass
  772. {
  773. vertex_shader = VSPos(id);
  774. pixel_shader = PSY800_Limited(frag_in);
  775. }
  776. }
  777. technique Y800_Full
  778. {
  779. pass
  780. {
  781. vertex_shader = VSPos(id);
  782. pixel_shader = PSY800_Full(frag_in);
  783. }
  784. }
  785. technique RGB_Limited
  786. {
  787. pass
  788. {
  789. vertex_shader = VSPos(id);
  790. pixel_shader = PSRGB_Limited(frag_in);
  791. }
  792. }
  793. technique BGR3_Limited
  794. {
  795. pass
  796. {
  797. vertex_shader = VSPos(id);
  798. pixel_shader = PSBGR3_Limited(frag_in);
  799. }
  800. }
  801. technique BGR3_Full
  802. {
  803. pass
  804. {
  805. vertex_shader = VSPos(id);
  806. pixel_shader = PSBGR3_Full(frag_in);
  807. }
  808. }