format_conversion.effect 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  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 float hlg_exponent;
  25. uniform float hdr_lw;
  26. uniform float hdr_lmax;
  27. uniform float4 color_vec0;
  28. uniform float4 color_vec1;
  29. uniform float4 color_vec2;
  30. uniform float3 color_range_min = {0.0, 0.0, 0.0};
  31. uniform float3 color_range_max = {1.0, 1.0, 1.0};
  32. uniform texture2d image;
  33. uniform texture2d image1;
  34. uniform texture2d image2;
  35. uniform texture2d image3;
  36. sampler_state def_sampler {
  37. Filter = Linear;
  38. AddressU = Clamp;
  39. AddressV = Clamp;
  40. };
  41. struct FragPos {
  42. float4 pos : POSITION;
  43. };
  44. struct VertTexPos {
  45. float2 uv : TEXCOORD0;
  46. float4 pos : POSITION;
  47. };
  48. struct VertPosWide {
  49. float3 pos_wide : TEXCOORD0;
  50. float4 pos : POSITION;
  51. };
  52. struct VertTexPosWide {
  53. float3 uuv : TEXCOORD0;
  54. float4 pos : POSITION;
  55. };
  56. struct VertTexPosWideWide {
  57. float4 uuvv : TEXCOORD0;
  58. float4 pos : POSITION;
  59. };
  60. struct FragTex {
  61. float2 uv : TEXCOORD0;
  62. };
  63. struct FragPosWide {
  64. float3 pos_wide : TEXCOORD0;
  65. };
  66. struct FragTexWide {
  67. float3 uuv : TEXCOORD0;
  68. };
  69. struct FragTexWideWide {
  70. float4 uuvv : TEXCOORD0;
  71. };
  72. FragPos VSPos(uint id : VERTEXID)
  73. {
  74. float idHigh = float(id >> 1);
  75. float idLow = float(id & uint(1));
  76. float x = idHigh * 4.0 - 1.0;
  77. float y = idLow * 4.0 - 1.0;
  78. FragPos vert_out;
  79. vert_out.pos = float4(x, y, 0.0, 1.0);
  80. return vert_out;
  81. }
  82. VertTexPosWide VSTexPos_Left(uint id : VERTEXID)
  83. {
  84. float idHigh = float(id >> 1);
  85. float idLow = float(id & uint(1));
  86. float x = idHigh * 4.0 - 1.0;
  87. float y = idLow * 4.0 - 1.0;
  88. float u_right = idHigh * 2.0;
  89. float u_left = u_right - width_i;
  90. float v = obs_glsl_compile ? (idLow * 2.0) : (1.0 - idLow * 2.0);
  91. VertTexPosWide vert_out;
  92. vert_out.uuv = float3(u_left, u_right, v);
  93. vert_out.pos = float4(x, y, 0.0, 1.0);
  94. return vert_out;
  95. }
  96. VertTexPosWideWide VSTexPos_TopLeft(uint id : VERTEXID)
  97. {
  98. float idHigh = float(id >> 1);
  99. float idLow = float(id & uint(1));
  100. float x = idHigh * 4.0 - 1.0;
  101. float y = idLow * 4.0 - 1.0;
  102. float u_right = idHigh * 2.0;
  103. float u_left = u_right - width_i;
  104. float v_bottom;
  105. float v_top;
  106. if (obs_glsl_compile) {
  107. v_bottom = idLow * 2.0;
  108. v_top = v_bottom + height_i;
  109. } else {
  110. v_bottom = 1.0 - idLow * 2.0;
  111. v_top = v_bottom - height_i;
  112. }
  113. VertTexPosWideWide vert_out;
  114. vert_out.uuvv = float4(u_left, u_right, v_top, v_bottom);
  115. vert_out.pos = float4(x, y, 0.0, 1.0);
  116. return vert_out;
  117. }
  118. VertTexPos VSTexPosHalf_Reverse(uint id : VERTEXID)
  119. {
  120. float idHigh = float(id >> 1);
  121. float idLow = float(id & uint(1));
  122. float x = idHigh * 4.0 - 1.0;
  123. float y = idLow * 4.0 - 1.0;
  124. float u = idHigh * 2.0;
  125. float v = obs_glsl_compile ? (idLow * 2.0) : (1.0 - idLow * 2.0);
  126. VertTexPos vert_out;
  127. vert_out.uv = float2(width_d2 * u, height * v);
  128. vert_out.pos = float4(x, y, 0.0, 1.0);
  129. return vert_out;
  130. }
  131. VertTexPos VSTexPosHalfHalf_Reverse(uint id : VERTEXID)
  132. {
  133. float idHigh = float(id >> 1);
  134. float idLow = float(id & uint(1));
  135. float x = idHigh * 4.0 - 1.0;
  136. float y = idLow * 4.0 - 1.0;
  137. float u = idHigh * 2.0;
  138. float v = obs_glsl_compile ? (idLow * 2.0) : (1.0 - idLow * 2.0);
  139. VertTexPos vert_out;
  140. vert_out.uv = float2(width_d2 * u, height_d2 * v);
  141. vert_out.pos = float4(x, y, 0.0, 1.0);
  142. return vert_out;
  143. }
  144. VertPosWide VSPosWide_Reverse(uint id : VERTEXID)
  145. {
  146. float idHigh = float(id >> 1);
  147. float idLow = float(id & uint(1));
  148. float x = idHigh * 4.0 - 1.0;
  149. float y = idLow * 4.0 - 1.0;
  150. float u = idHigh * 2.0;
  151. float v = obs_glsl_compile ? (idLow * 2.0) : (1.0 - idLow * 2.0);
  152. VertPosWide vert_out;
  153. vert_out.pos_wide = float3(float2(width, width_d2) * u, height * v);
  154. vert_out.pos = float4(x, y, 0.0, 1.0);
  155. return vert_out;
  156. }
  157. float PS_Y(FragPos frag_in) : TARGET
  158. {
  159. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  160. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  161. return y;
  162. }
  163. float PS_P010_PQ_Y_709_2020(FragPos frag_in) : TARGET
  164. {
  165. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb * sdr_white_nits_over_maximum;
  166. rgb = rec709_to_rec2020(rgb);
  167. rgb = linear_to_st2084(rgb);
  168. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  169. y = floor(saturate(y) * 1023. + 0.5) * (64. / 65535.);
  170. return y;
  171. }
  172. float PS_P010_HLG_Y_709_2020(FragPos frag_in) : TARGET
  173. {
  174. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb * sdr_white_nits_over_maximum;
  175. rgb = rec709_to_rec2020(rgb);
  176. rgb = linear_to_hlg(rgb, hdr_lw);
  177. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  178. y = floor(saturate(y) * 1023. + 0.5) * (64. / 65535.);
  179. return y;
  180. }
  181. float PS_P010_SRGB_Y(FragPos frag_in) : TARGET
  182. {
  183. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  184. rgb = srgb_linear_to_nonlinear(rgb);
  185. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  186. y = floor(saturate(y) * 1023. + 0.5) * (64. / 65535.);
  187. return y;
  188. }
  189. float PS_I010_PQ_Y_709_2020(FragPos frag_in) : TARGET
  190. {
  191. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb * sdr_white_nits_over_maximum;
  192. rgb = rec709_to_rec2020(rgb);
  193. rgb = linear_to_st2084(rgb);
  194. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  195. return y * (1023. / 65535.);
  196. }
  197. float PS_I010_HLG_Y_709_2020(FragPos frag_in) : TARGET
  198. {
  199. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb * sdr_white_nits_over_maximum;
  200. rgb = rec709_to_rec2020(rgb);
  201. rgb = linear_to_hlg(rgb, hdr_lw);
  202. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  203. return y * (1023. / 65535.);
  204. }
  205. float PS_I010_SRGB_Y(FragPos frag_in) : TARGET
  206. {
  207. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  208. rgb = srgb_linear_to_nonlinear(rgb);
  209. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  210. return y * (1023. / 65535.);
  211. }
  212. float2 PS_UV_Wide(FragTexWide frag_in) : TARGET
  213. {
  214. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  215. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  216. float3 rgb = (rgb_left + rgb_right) * 0.5;
  217. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  218. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  219. return float2(u, v);
  220. }
  221. float2 PS_P010_PQ_UV_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  222. {
  223. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  224. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  225. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  226. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  227. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  228. rgb = rec709_to_rec2020(rgb);
  229. rgb = linear_to_st2084(rgb);
  230. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  231. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  232. float2 uv = float2(u, v);
  233. uv = floor(saturate(uv) * 1023. + 0.5) * (64. / 65535.);
  234. return uv;
  235. }
  236. float2 PS_P010_HLG_UV_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  237. {
  238. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  239. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  240. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  241. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  242. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  243. rgb = rec709_to_rec2020(rgb);
  244. rgb = linear_to_hlg(rgb, hdr_lw);
  245. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  246. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  247. float2 uv = float2(u, v);
  248. uv = floor(saturate(uv) * 1023. + 0.5) * (64. / 65535.);
  249. return uv;
  250. }
  251. float2 PS_P010_SRGB_UV_Wide(FragTexWide frag_in) : TARGET
  252. {
  253. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  254. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  255. float3 rgb = (rgb_left + rgb_right) * 0.5;
  256. rgb = srgb_linear_to_nonlinear(rgb);
  257. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  258. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  259. float2 uv = float2(u, v);
  260. uv = floor(saturate(uv) * 1023. + 0.5) * (64. / 65535.);
  261. return uv;
  262. }
  263. float PS_U(FragPos frag_in) : TARGET
  264. {
  265. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  266. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  267. return u;
  268. }
  269. float PS_V(FragPos frag_in) : TARGET
  270. {
  271. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  272. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  273. return v;
  274. }
  275. float PS_U_Wide(FragTexWide frag_in) : TARGET
  276. {
  277. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  278. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  279. float3 rgb = (rgb_left + rgb_right) * 0.5;
  280. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  281. return u;
  282. }
  283. float PS_V_Wide(FragTexWide frag_in) : TARGET
  284. {
  285. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  286. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  287. float3 rgb = (rgb_left + rgb_right) * 0.5;
  288. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  289. return v;
  290. }
  291. float PS_I010_PQ_U_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  292. {
  293. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  294. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  295. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  296. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  297. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  298. rgb = rec709_to_rec2020(rgb);
  299. rgb = linear_to_st2084(rgb);
  300. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  301. return u * (1023. / 65535.);
  302. }
  303. float PS_I010_HLG_U_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  304. {
  305. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  306. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  307. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  308. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  309. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  310. rgb = rec709_to_rec2020(rgb);
  311. rgb = linear_to_hlg(rgb, hdr_lw);
  312. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  313. return u * (1023. / 65535.);
  314. }
  315. float PS_I010_SRGB_U_Wide(FragTexWide frag_in) : TARGET
  316. {
  317. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  318. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  319. float3 rgb = (rgb_left + rgb_right) * 0.5;
  320. rgb = srgb_linear_to_nonlinear(rgb);
  321. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  322. return u * (1023. / 65535.);
  323. }
  324. float PS_I010_PQ_V_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  325. {
  326. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  327. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  328. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  329. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  330. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  331. rgb = rec709_to_rec2020(rgb);
  332. rgb = linear_to_st2084(rgb);
  333. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  334. return v * (1023. / 65535.);
  335. }
  336. float PS_I010_HLG_V_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  337. {
  338. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  339. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  340. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  341. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  342. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  343. rgb = rec709_to_rec2020(rgb);
  344. rgb = linear_to_hlg(rgb, hdr_lw);
  345. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  346. return v * (1023. / 65535.);
  347. }
  348. float PS_I010_SRGB_V_Wide(FragTexWide frag_in) : TARGET
  349. {
  350. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  351. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  352. float3 rgb = (rgb_left + rgb_right) * 0.5;
  353. rgb = srgb_linear_to_nonlinear(rgb);
  354. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  355. return v * (1023. / 65535.);
  356. }
  357. float3 YUV_to_RGB(float3 yuv)
  358. {
  359. yuv = clamp(yuv, color_range_min, color_range_max);
  360. float r = dot(color_vec0.xyz, yuv) + color_vec0.w;
  361. float g = dot(color_vec1.xyz, yuv) + color_vec1.w;
  362. float b = dot(color_vec2.xyz, yuv) + color_vec2.w;
  363. return float3(r, g, b);
  364. }
  365. float3 PSUYVY_Reverse(FragTex frag_in) : TARGET
  366. {
  367. float4 y2uv = image.Load(int3(frag_in.uv.xy, 0));
  368. float2 y01 = y2uv.yw;
  369. float2 cbcr = y2uv.zx;
  370. float leftover = frac(frag_in.uv.x);
  371. float y = (leftover < 0.5) ? y01.x : y01.y;
  372. float3 yuv = float3(y, cbcr);
  373. float3 rgb = YUV_to_RGB(yuv);
  374. return rgb;
  375. }
  376. float3 PSYUY2_Reverse(FragTex frag_in) : TARGET
  377. {
  378. float4 y2uv = image.Load(int3(frag_in.uv.xy, 0));
  379. float2 y01 = y2uv.zx;
  380. float2 cbcr = y2uv.yw;
  381. float leftover = frac(frag_in.uv.x);
  382. float y = (leftover < 0.5) ? y01.x : y01.y;
  383. float3 yuv = float3(y, cbcr);
  384. float3 rgb = YUV_to_RGB(yuv);
  385. return rgb;
  386. }
  387. float3 PSYVYU_Reverse(FragTex frag_in) : TARGET
  388. {
  389. float4 y2uv = image.Load(int3(frag_in.uv.xy, 0));
  390. float2 y01 = y2uv.zx;
  391. float2 cbcr = y2uv.wy;
  392. float leftover = frac(frag_in.uv.x);
  393. float y = (leftover < 0.5) ? y01.x : y01.y;
  394. float3 yuv = float3(y, cbcr);
  395. float3 rgb = YUV_to_RGB(yuv);
  396. return rgb;
  397. }
  398. float3 PSPlanar420_Reverse(VertTexPos frag_in) : TARGET
  399. {
  400. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  401. int3 xy0_chroma = int3(frag_in.uv, 0);
  402. float cb = image1.Load(xy0_chroma).x;
  403. float cr = image2.Load(xy0_chroma).x;
  404. float3 yuv = float3(y, cb, cr);
  405. float3 rgb = YUV_to_RGB(yuv);
  406. return rgb;
  407. }
  408. float4 PSPlanar420_PQ_Reverse(VertTexPos frag_in) : TARGET
  409. {
  410. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  411. int3 xy0_chroma = int3(frag_in.uv, 0);
  412. float cb = image1.Load(xy0_chroma).x;
  413. float cr = image2.Load(xy0_chroma).x;
  414. float3 yuv = float3(y, cb, cr);
  415. float3 pq = YUV_to_RGB(yuv);
  416. float3 hdr2020 = st2084_to_linear_eetf(pq, hdr_lw, hdr_lmax) * maximum_over_sdr_white_nits;
  417. float3 rgb = rec2020_to_rec709(hdr2020);
  418. return float4(rgb, 1.);
  419. }
  420. float4 PSPlanar420A_Reverse(VertTexPos frag_in) : TARGET
  421. {
  422. int3 xy0_luma = int3(frag_in.pos.xy, 0);
  423. float y = image.Load(xy0_luma).x;
  424. int3 xy0_chroma = int3(frag_in.uv, 0);
  425. float cb = image1.Load(xy0_chroma).x;
  426. float cr = image2.Load(xy0_chroma).x;
  427. float alpha = image3.Load(xy0_luma).x;
  428. float3 yuv = float3(y, cb, cr);
  429. float4 rgba = float4(YUV_to_RGB(yuv), alpha);
  430. return rgba;
  431. }
  432. float3 PSPlanar422_Reverse(FragPosWide frag_in) : TARGET
  433. {
  434. float y = image.Load(int3(frag_in.pos_wide.xz, 0)).x;
  435. int3 xy0_chroma = int3(frag_in.pos_wide.yz, 0);
  436. float cb = image1.Load(xy0_chroma).x;
  437. float cr = image2.Load(xy0_chroma).x;
  438. float3 yuv = float3(y, cb, cr);
  439. float3 rgb = YUV_to_RGB(yuv);
  440. return rgb;
  441. }
  442. float4 PSPlanar422_10LE_Reverse(FragPosWide frag_in) : TARGET
  443. {
  444. float y = image.Load(int3(frag_in.pos_wide.xz, 0)).x;
  445. int3 xy0_chroma = int3(frag_in.pos_wide.yz, 0);
  446. float cb = image1.Load(xy0_chroma).x;
  447. float cr = image2.Load(xy0_chroma).x;
  448. float3 yuv = float3(y, cb, cr);
  449. yuv *= 65535. / 1023.;
  450. float3 rgb = YUV_to_RGB(yuv);
  451. rgb = srgb_nonlinear_to_linear(rgb);
  452. return float4(rgb, 1.);
  453. }
  454. float4 PSPlanar422A_Reverse(FragPosWide frag_in) : TARGET
  455. {
  456. int3 xy0_luma = int3(frag_in.pos_wide.xz, 0);
  457. float y = image.Load(xy0_luma).x;
  458. int3 xy0_chroma = int3(frag_in.pos_wide.yz, 0);
  459. float cb = image1.Load(xy0_chroma).x;
  460. float cr = image2.Load(xy0_chroma).x;
  461. float alpha = image3.Load(xy0_luma).x;
  462. float3 yuv = float3(y, cb, cr);
  463. float4 rgba = float4(YUV_to_RGB(yuv), alpha);
  464. return rgba;
  465. }
  466. float3 PSPlanar444_Reverse(FragPos frag_in) : TARGET
  467. {
  468. int3 xy0 = int3(frag_in.pos.xy, 0);
  469. float y = image.Load(xy0).x;
  470. float cb = image1.Load(xy0).x;
  471. float cr = image2.Load(xy0).x;
  472. float3 yuv = float3(y, cb, cr);
  473. float3 rgb = YUV_to_RGB(yuv);
  474. return rgb;
  475. }
  476. float4 PSPlanar444_12LE_Reverse(FragPos frag_in) : TARGET
  477. {
  478. int3 xy0 = int3(frag_in.pos.xy, 0);
  479. float y = image.Load(xy0).x;
  480. float cb = image1.Load(xy0).x;
  481. float cr = image2.Load(xy0).x;
  482. float3 yuv = float3(y, cb, cr);
  483. yuv *= 65535. / 4095.;
  484. float3 rgb = YUV_to_RGB(yuv);
  485. rgb = srgb_nonlinear_to_linear(rgb);
  486. return float4(rgb, 1.);
  487. }
  488. float4 PSPlanar444A_Reverse(FragPos frag_in) : TARGET
  489. {
  490. int3 xy0 = int3(frag_in.pos.xy, 0);
  491. float y = image.Load(xy0).x;
  492. float cb = image1.Load(xy0).x;
  493. float cr = image2.Load(xy0).x;
  494. float alpha = image3.Load(xy0).x;
  495. float3 yuv = float3(y, cb, cr);
  496. float4 rgba = float4(YUV_to_RGB(yuv), alpha);
  497. return rgba;
  498. }
  499. float4 PSPlanar444A_12LE_Reverse(FragPos frag_in) : TARGET
  500. {
  501. int3 xy0 = int3(frag_in.pos.xy, 0);
  502. float y = image.Load(xy0).x;
  503. float cb = image1.Load(xy0).x;
  504. float cr = image2.Load(xy0).x;
  505. float alpha = image3.Load(xy0).x * 16.;
  506. float3 yuv = float3(y, cb, cr);
  507. yuv *= 65535. / 4095.;
  508. float3 rgb = YUV_to_RGB(yuv);
  509. rgb = srgb_nonlinear_to_linear(rgb);
  510. return float4(rgb, alpha);
  511. }
  512. float4 PSAYUV_Reverse(FragPos frag_in) : TARGET
  513. {
  514. float4 yuva = image.Load(int3(frag_in.pos.xy, 0));
  515. float4 rgba = float4(YUV_to_RGB(yuva.xyz), yuva.a);
  516. return rgba;
  517. }
  518. float3 PSNV12_Reverse(VertTexPos frag_in) : TARGET
  519. {
  520. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  521. float2 cbcr = image1.Load(int3(frag_in.uv, 0)).xy;
  522. float3 yuv = float3(y, cbcr);
  523. float3 rgb = YUV_to_RGB(yuv);
  524. return rgb;
  525. }
  526. float4 PSI010_SRGB_Reverse(VertTexPos frag_in) : TARGET
  527. {
  528. float ratio = 65535. / 1023.;
  529. float y = image.Load(int3(frag_in.pos.xy, 0)).x * ratio;
  530. int3 xy0_chroma = int3(frag_in.uv, 0);
  531. float cb = image1.Load(xy0_chroma).x * ratio;
  532. float cr = image2.Load(xy0_chroma).x * ratio;
  533. float3 yuv = float3(y, cb, cr);
  534. float3 rgb = YUV_to_RGB(yuv);
  535. rgb = srgb_nonlinear_to_linear(rgb);
  536. return float4(rgb, 1.);
  537. }
  538. float4 PSI010_PQ_2020_709_Reverse(VertTexPos frag_in) : TARGET
  539. {
  540. float ratio = 65535. / 1023.;
  541. float y = image.Load(int3(frag_in.pos.xy, 0)).x * ratio;
  542. int3 xy0_chroma = int3(frag_in.uv, 0);
  543. float cb = image1.Load(xy0_chroma).x * ratio;
  544. float cr = image2.Load(xy0_chroma).x * ratio;
  545. float3 yuv = float3(y, cb, cr);
  546. float3 pq = YUV_to_RGB(yuv);
  547. float3 hdr2020 = st2084_to_linear_eetf(pq, hdr_lw, hdr_lmax) * maximum_over_sdr_white_nits;
  548. float3 rgb = rec2020_to_rec709(hdr2020);
  549. return float4(rgb, 1.);
  550. }
  551. float4 PSI010_HLG_2020_709_Reverse(VertTexPos frag_in) : TARGET
  552. {
  553. float ratio = 65535. / 1023.;
  554. float y = image.Load(int3(frag_in.pos.xy, 0)).x * ratio;
  555. int3 xy0_chroma = int3(frag_in.uv, 0);
  556. float cb = image1.Load(xy0_chroma).x * ratio;
  557. float cr = image2.Load(xy0_chroma).x * ratio;
  558. float3 yuv = float3(y, cb, cr);
  559. float3 hlg = YUV_to_RGB(yuv);
  560. float3 hdr2020 = hlg_to_linear(hlg, hlg_exponent) * maximum_over_sdr_white_nits;
  561. float3 rgb = rec2020_to_rec709(hdr2020);
  562. return float4(rgb, 1.);
  563. }
  564. float4 PSP010_SRGB_Reverse(VertTexPos frag_in) : TARGET
  565. {
  566. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  567. float2 cbcr = image1.Load(int3(frag_in.uv, 0)).xy;
  568. float3 yuv_65535 = floor(float3(y, cbcr) * 65535. + 0.5);
  569. float3 yuv_1023 = floor(yuv_65535 * 0.015625);
  570. float3 yuv = yuv_1023 / 1023.;
  571. float3 rgb = YUV_to_RGB(yuv);
  572. rgb = srgb_nonlinear_to_linear(rgb);
  573. return float4(rgb, 1.);
  574. }
  575. float4 PSP010_PQ_2020_709_Reverse(VertTexPos frag_in) : TARGET
  576. {
  577. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  578. float2 cbcr = image1.Load(int3(frag_in.uv, 0)).xy;
  579. float3 yuv_65535 = floor(float3(y, cbcr) * 65535. + 0.5);
  580. float3 yuv_1023 = floor(yuv_65535 * 0.015625);
  581. float3 yuv = yuv_1023 / 1023.;
  582. float3 pq = YUV_to_RGB(yuv);
  583. float3 hdr2020 = st2084_to_linear_eetf(pq, hdr_lw, hdr_lmax) * maximum_over_sdr_white_nits;
  584. float3 rgb = rec2020_to_rec709(hdr2020);
  585. return float4(rgb, 1.);
  586. }
  587. float4 PSP010_HLG_2020_709_Reverse(VertTexPos frag_in) : TARGET
  588. {
  589. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  590. float2 cbcr = image1.Load(int3(frag_in.uv, 0)).xy;
  591. float3 yuv_65535 = floor(float3(y, cbcr) * 65535. + 0.5);
  592. float3 yuv_1023 = floor(yuv_65535 * 0.015625);
  593. float3 yuv = yuv_1023 / 1023.;
  594. float3 hlg = YUV_to_RGB(yuv);
  595. float3 hdr2020 = hlg_to_linear(hlg, hlg_exponent) * maximum_over_sdr_white_nits;
  596. float3 rgb = rec2020_to_rec709(hdr2020);
  597. return float4(rgb, 1.);
  598. }
  599. float3 PSY800_Limited(FragPos frag_in) : TARGET
  600. {
  601. float limited = image.Load(int3(frag_in.pos.xy, 0)).x;
  602. float full = (255.0 / 219.0) * limited - (16.0 / 219.0);
  603. return float3(full, full, full);
  604. }
  605. float3 PSY800_Full(FragPos frag_in) : TARGET
  606. {
  607. float3 full = image.Load(int3(frag_in.pos.xy, 0)).xxx;
  608. return full;
  609. }
  610. float4 PSRGB_Limited(FragPos frag_in) : TARGET
  611. {
  612. float4 rgba = image.Load(int3(frag_in.pos.xy, 0));
  613. rgba.rgb = (255.0 / 219.0) * rgba.rgb - (16.0 / 219.0);
  614. return rgba;
  615. }
  616. float3 PSBGR3_Limited(FragPos frag_in) : TARGET
  617. {
  618. float x = frag_in.pos.x * 3.0;
  619. float y = frag_in.pos.y;
  620. float b = image.Load(int3(x - 1.0, y, 0)).x;
  621. float g = image.Load(int3(x, y, 0)).x;
  622. float r = image.Load(int3(x + 1.0, y, 0)).x;
  623. float3 rgb = float3(r, g, b);
  624. rgb = (255.0 / 219.0) * rgb - (16.0 / 219.0);
  625. return rgb;
  626. }
  627. float3 PSBGR3_Full(FragPos frag_in) : TARGET
  628. {
  629. float x = frag_in.pos.x * 3.0;
  630. float y = frag_in.pos.y;
  631. float b = image.Load(int3(x - 1.0, y, 0)).x;
  632. float g = image.Load(int3(x, y, 0)).x;
  633. float r = image.Load(int3(x + 1.0, y, 0)).x;
  634. float3 rgb = float3(r, g, b);
  635. return rgb;
  636. }
  637. technique Planar_Y
  638. {
  639. pass
  640. {
  641. vertex_shader = VSPos(id);
  642. pixel_shader = PS_Y(frag_in);
  643. }
  644. }
  645. technique Planar_U
  646. {
  647. pass
  648. {
  649. vertex_shader = VSPos(id);
  650. pixel_shader = PS_U(frag_in);
  651. }
  652. }
  653. technique Planar_V
  654. {
  655. pass
  656. {
  657. vertex_shader = VSPos(id);
  658. pixel_shader = PS_V(frag_in);
  659. }
  660. }
  661. technique Planar_U_Left
  662. {
  663. pass
  664. {
  665. vertex_shader = VSTexPos_Left(id);
  666. pixel_shader = PS_U_Wide(frag_in);
  667. }
  668. }
  669. technique Planar_V_Left
  670. {
  671. pass
  672. {
  673. vertex_shader = VSTexPos_Left(id);
  674. pixel_shader = PS_V_Wide(frag_in);
  675. }
  676. }
  677. technique NV12_Y
  678. {
  679. pass
  680. {
  681. vertex_shader = VSPos(id);
  682. pixel_shader = PS_Y(frag_in);
  683. }
  684. }
  685. technique NV12_UV
  686. {
  687. pass
  688. {
  689. vertex_shader = VSTexPos_Left(id);
  690. pixel_shader = PS_UV_Wide(frag_in);
  691. }
  692. }
  693. technique I010_PQ_Y
  694. {
  695. pass
  696. {
  697. vertex_shader = VSPos(id);
  698. pixel_shader = PS_I010_PQ_Y_709_2020(frag_in);
  699. }
  700. }
  701. technique I010_HLG_Y
  702. {
  703. pass
  704. {
  705. vertex_shader = VSPos(id);
  706. pixel_shader = PS_I010_HLG_Y_709_2020(frag_in);
  707. }
  708. }
  709. technique I010_SRGB_Y
  710. {
  711. pass
  712. {
  713. vertex_shader = VSPos(id);
  714. pixel_shader = PS_I010_SRGB_Y(frag_in);
  715. }
  716. }
  717. technique I010_PQ_U
  718. {
  719. pass
  720. {
  721. vertex_shader = VSTexPos_TopLeft(id);
  722. pixel_shader = PS_I010_PQ_U_709_2020_WideWide(frag_in);
  723. }
  724. }
  725. technique I010_HLG_U
  726. {
  727. pass
  728. {
  729. vertex_shader = VSTexPos_TopLeft(id);
  730. pixel_shader = PS_I010_HLG_U_709_2020_WideWide(frag_in);
  731. }
  732. }
  733. technique I010_SRGB_U
  734. {
  735. pass
  736. {
  737. vertex_shader = VSTexPos_Left(id);
  738. pixel_shader = PS_I010_SRGB_U_Wide(frag_in);
  739. }
  740. }
  741. technique I010_PQ_V
  742. {
  743. pass
  744. {
  745. vertex_shader = VSTexPos_TopLeft(id);
  746. pixel_shader = PS_I010_PQ_V_709_2020_WideWide(frag_in);
  747. }
  748. }
  749. technique I010_HLG_V
  750. {
  751. pass
  752. {
  753. vertex_shader = VSTexPos_TopLeft(id);
  754. pixel_shader = PS_I010_HLG_V_709_2020_WideWide(frag_in);
  755. }
  756. }
  757. technique I010_SRGB_V
  758. {
  759. pass
  760. {
  761. vertex_shader = VSTexPos_Left(id);
  762. pixel_shader = PS_I010_SRGB_V_Wide(frag_in);
  763. }
  764. }
  765. technique P010_PQ_Y
  766. {
  767. pass
  768. {
  769. vertex_shader = VSPos(id);
  770. pixel_shader = PS_P010_PQ_Y_709_2020(frag_in);
  771. }
  772. }
  773. technique P010_HLG_Y
  774. {
  775. pass
  776. {
  777. vertex_shader = VSPos(id);
  778. pixel_shader = PS_P010_HLG_Y_709_2020(frag_in);
  779. }
  780. }
  781. technique P010_SRGB_Y
  782. {
  783. pass
  784. {
  785. vertex_shader = VSPos(id);
  786. pixel_shader = PS_P010_SRGB_Y(frag_in);
  787. }
  788. }
  789. technique P010_PQ_UV
  790. {
  791. pass
  792. {
  793. vertex_shader = VSTexPos_TopLeft(id);
  794. pixel_shader = PS_P010_PQ_UV_709_2020_WideWide(frag_in);
  795. }
  796. }
  797. technique P010_HLG_UV
  798. {
  799. pass
  800. {
  801. vertex_shader = VSTexPos_TopLeft(id);
  802. pixel_shader = PS_P010_HLG_UV_709_2020_WideWide(frag_in);
  803. }
  804. }
  805. technique P010_SRGB_UV
  806. {
  807. pass
  808. {
  809. vertex_shader = VSTexPos_Left(id);
  810. pixel_shader = PS_P010_SRGB_UV_Wide(frag_in);
  811. }
  812. }
  813. technique UYVY_Reverse
  814. {
  815. pass
  816. {
  817. vertex_shader = VSTexPosHalf_Reverse(id);
  818. pixel_shader = PSUYVY_Reverse(frag_in);
  819. }
  820. }
  821. technique YUY2_Reverse
  822. {
  823. pass
  824. {
  825. vertex_shader = VSTexPosHalf_Reverse(id);
  826. pixel_shader = PSYUY2_Reverse(frag_in);
  827. }
  828. }
  829. technique YVYU_Reverse
  830. {
  831. pass
  832. {
  833. vertex_shader = VSTexPosHalf_Reverse(id);
  834. pixel_shader = PSYVYU_Reverse(frag_in);
  835. }
  836. }
  837. technique I420_Reverse
  838. {
  839. pass
  840. {
  841. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  842. pixel_shader = PSPlanar420_Reverse(frag_in);
  843. }
  844. }
  845. technique I420_PQ_Reverse
  846. {
  847. pass
  848. {
  849. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  850. pixel_shader = PSPlanar420_PQ_Reverse(frag_in);
  851. }
  852. }
  853. technique I40A_Reverse
  854. {
  855. pass
  856. {
  857. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  858. pixel_shader = PSPlanar420A_Reverse(frag_in);
  859. }
  860. }
  861. technique I422_Reverse
  862. {
  863. pass
  864. {
  865. vertex_shader = VSPosWide_Reverse(id);
  866. pixel_shader = PSPlanar422_Reverse(frag_in);
  867. }
  868. }
  869. technique I210_Reverse
  870. {
  871. pass
  872. {
  873. vertex_shader = VSPosWide_Reverse(id);
  874. pixel_shader = PSPlanar422_10LE_Reverse(frag_in);
  875. }
  876. }
  877. technique I42A_Reverse
  878. {
  879. pass
  880. {
  881. vertex_shader = VSPosWide_Reverse(id);
  882. pixel_shader = PSPlanar422A_Reverse(frag_in);
  883. }
  884. }
  885. technique I444_Reverse
  886. {
  887. pass
  888. {
  889. vertex_shader = VSPos(id);
  890. pixel_shader = PSPlanar444_Reverse(frag_in);
  891. }
  892. }
  893. technique I412_Reverse
  894. {
  895. pass
  896. {
  897. vertex_shader = VSPos(id);
  898. pixel_shader = PSPlanar444_12LE_Reverse(frag_in);
  899. }
  900. }
  901. technique YUVA_Reverse
  902. {
  903. pass
  904. {
  905. vertex_shader = VSPos(id);
  906. pixel_shader = PSPlanar444A_Reverse(frag_in);
  907. }
  908. }
  909. technique YA2L_Reverse
  910. {
  911. pass
  912. {
  913. vertex_shader = VSPos(id);
  914. pixel_shader = PSPlanar444A_12LE_Reverse(frag_in);
  915. }
  916. }
  917. technique AYUV_Reverse
  918. {
  919. pass
  920. {
  921. vertex_shader = VSPos(id);
  922. pixel_shader = PSAYUV_Reverse(frag_in);
  923. }
  924. }
  925. technique NV12_Reverse
  926. {
  927. pass
  928. {
  929. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  930. pixel_shader = PSNV12_Reverse(frag_in);
  931. }
  932. }
  933. technique I010_SRGB_Reverse
  934. {
  935. pass
  936. {
  937. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  938. pixel_shader = PSI010_SRGB_Reverse(frag_in);
  939. }
  940. }
  941. technique I010_PQ_2020_709_Reverse
  942. {
  943. pass
  944. {
  945. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  946. pixel_shader = PSI010_PQ_2020_709_Reverse(frag_in);
  947. }
  948. }
  949. technique I010_HLG_2020_709_Reverse
  950. {
  951. pass
  952. {
  953. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  954. pixel_shader = PSI010_HLG_2020_709_Reverse(frag_in);
  955. }
  956. }
  957. technique P010_SRGB_Reverse
  958. {
  959. pass
  960. {
  961. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  962. pixel_shader = PSP010_SRGB_Reverse(frag_in);
  963. }
  964. }
  965. technique P010_PQ_2020_709_Reverse
  966. {
  967. pass
  968. {
  969. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  970. pixel_shader = PSP010_PQ_2020_709_Reverse(frag_in);
  971. }
  972. }
  973. technique P010_HLG_2020_709_Reverse
  974. {
  975. pass
  976. {
  977. vertex_shader = VSTexPosHalfHalf_Reverse(id);
  978. pixel_shader = PSP010_HLG_2020_709_Reverse(frag_in);
  979. }
  980. }
  981. technique Y800_Limited
  982. {
  983. pass
  984. {
  985. vertex_shader = VSPos(id);
  986. pixel_shader = PSY800_Limited(frag_in);
  987. }
  988. }
  989. technique Y800_Full
  990. {
  991. pass
  992. {
  993. vertex_shader = VSPos(id);
  994. pixel_shader = PSY800_Full(frag_in);
  995. }
  996. }
  997. technique RGB_Limited
  998. {
  999. pass
  1000. {
  1001. vertex_shader = VSPos(id);
  1002. pixel_shader = PSRGB_Limited(frag_in);
  1003. }
  1004. }
  1005. technique BGR3_Limited
  1006. {
  1007. pass
  1008. {
  1009. vertex_shader = VSPos(id);
  1010. pixel_shader = PSBGR3_Limited(frag_in);
  1011. }
  1012. }
  1013. technique BGR3_Full
  1014. {
  1015. pass
  1016. {
  1017. vertex_shader = VSPos(id);
  1018. pixel_shader = PSBGR3_Full(frag_in);
  1019. }
  1020. }