format_conversion.effect 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590
  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 height_x2_i;
  23. uniform float maximum_over_sdr_white_nits;
  24. uniform float sdr_white_nits_over_maximum;
  25. uniform float hlg_exponent;
  26. uniform float hdr_lw;
  27. uniform float hdr_lmax;
  28. uniform float4 color_vec0;
  29. uniform float4 color_vec1;
  30. uniform float4 color_vec2;
  31. uniform float3 color_range_min = {0.0, 0.0, 0.0};
  32. uniform float3 color_range_max = {1.0, 1.0, 1.0};
  33. uniform texture2d image;
  34. uniform texture2d image1;
  35. uniform texture2d image2;
  36. uniform texture2d image3;
  37. sampler_state def_sampler {
  38. Filter = Linear;
  39. AddressU = Clamp;
  40. AddressV = Clamp;
  41. };
  42. struct FragPos {
  43. float4 pos : POSITION;
  44. };
  45. struct VertTexPos {
  46. float2 uv : TEXCOORD0;
  47. float4 pos : POSITION;
  48. };
  49. struct VertTexTexPos {
  50. float4 uvuv : TEXCOORD0;
  51. float4 pos : POSITION;
  52. };
  53. struct VertTexPosWide {
  54. float3 uuv : TEXCOORD0;
  55. float4 pos : POSITION;
  56. };
  57. struct VertTexPosWideWide {
  58. float4 uuvv : TEXCOORD0;
  59. float4 pos : POSITION;
  60. };
  61. struct FragTex {
  62. float2 uv : TEXCOORD0;
  63. };
  64. struct FragTexTex {
  65. float4 uvuv : TEXCOORD0;
  66. };
  67. struct FragTexWide {
  68. float3 uuv : TEXCOORD0;
  69. };
  70. struct FragTexWideWide {
  71. float4 uuvv : TEXCOORD0;
  72. };
  73. FragPos VSPos(uint id : VERTEXID)
  74. {
  75. float idHigh = float(id >> 1);
  76. float idLow = float(id & uint(1));
  77. float x = idHigh * 4.0 - 1.0;
  78. float y = idLow * 4.0 - 1.0;
  79. FragPos vert_out;
  80. vert_out.pos = float4(x, y, 0.0, 1.0);
  81. return vert_out;
  82. }
  83. VertTexPosWide VSTexPos_Left(uint id : VERTEXID)
  84. {
  85. float idHigh = float(id >> 1);
  86. float idLow = float(id & uint(1));
  87. float x = idHigh * 4.0 - 1.0;
  88. float y = idLow * 4.0 - 1.0;
  89. float u_right = idHigh * 2.0;
  90. float u_left = u_right - width_i;
  91. float v = obs_glsl_compile ? (idLow * 2.0) : (1.0 - idLow * 2.0);
  92. VertTexPosWide vert_out;
  93. vert_out.uuv = float3(u_left, u_right, v);
  94. vert_out.pos = float4(x, y, 0.0, 1.0);
  95. return vert_out;
  96. }
  97. VertTexPosWideWide VSTexPos_TopLeft(uint id : VERTEXID)
  98. {
  99. float idHigh = float(id >> 1);
  100. float idLow = float(id & uint(1));
  101. float x = idHigh * 4.0 - 1.0;
  102. float y = idLow * 4.0 - 1.0;
  103. float u_right = idHigh * 2.0;
  104. float u_left = u_right - width_i;
  105. float v_bottom;
  106. float v_top;
  107. if (obs_glsl_compile) {
  108. v_bottom = idLow * 2.0;
  109. v_top = v_bottom + height_i;
  110. } else {
  111. v_bottom = 1.0 - idLow * 2.0;
  112. v_top = v_bottom - height_i;
  113. }
  114. VertTexPosWideWide vert_out;
  115. vert_out.uuvv = float4(u_left, u_right, v_top, v_bottom);
  116. vert_out.pos = float4(x, y, 0.0, 1.0);
  117. return vert_out;
  118. }
  119. VertTexTexPos VSPacked422Left_Reverse(uint id : VERTEXID)
  120. {
  121. float idHigh = float(id >> 1);
  122. float idLow = float(id & uint(1));
  123. float x = idHigh * 4. - 1.;
  124. float y = idLow * 4. - 1.;
  125. float u = idHigh * 2. + width_x2_i;
  126. float v = idLow * 2.;
  127. v = obs_glsl_compile ? v : (1. - v);
  128. VertTexTexPos vert_out;
  129. vert_out.uvuv = float4(width_d2 * u, height * v, u, v);
  130. vert_out.pos = float4(x, y, 0., 1.);
  131. return vert_out;
  132. }
  133. VertTexPos VS420Left_Reverse(uint id : VERTEXID)
  134. {
  135. float idHigh = float(id >> 1);
  136. float idLow = float(id & uint(1));
  137. float x = idHigh * 4. - 1.;
  138. float y = idLow * 4. - 1.;
  139. float u = idHigh * 2. + width_x2_i;
  140. float v = idLow * 2.;
  141. v = obs_glsl_compile ? v : (1. - v);
  142. VertTexPos vert_out;
  143. vert_out.uv = float2(u, v);
  144. vert_out.pos = float4(x, y, 0., 1.);
  145. return vert_out;
  146. }
  147. VertTexPos VS420TopLeft_Reverse(uint id : VERTEXID)
  148. {
  149. float idHigh = float(id >> 1);
  150. float idLow = float(id & uint(1));
  151. float x = idHigh * 4. - 1.;
  152. float y = idLow * 4. - 1.;
  153. float u = idHigh * 2. + width_x2_i;
  154. float v = idLow * 2. - height_x2_i;
  155. v = obs_glsl_compile ? v : (1. - v);
  156. VertTexPos vert_out;
  157. vert_out.uv = float2(u, v);
  158. vert_out.pos = float4(x, y, 0., 1.);
  159. return vert_out;
  160. }
  161. VertTexPos VS422Left_Reverse(uint id : VERTEXID)
  162. {
  163. float idHigh = float(id >> 1);
  164. float idLow = float(id & uint(1));
  165. float x = idHigh * 4.0 - 1.0;
  166. float y = idLow * 4.0 - 1.0;
  167. float u = idHigh * 2.0 + width_x2_i;
  168. float v = obs_glsl_compile ? (idLow * 2.0) : (1.0 - idLow * 2.0);
  169. VertTexPos vert_out;
  170. vert_out.uv = float2(u, v);
  171. vert_out.pos = float4(x, y, 0.0, 1.0);
  172. return vert_out;
  173. }
  174. float PS_Y(FragPos frag_in) : TARGET
  175. {
  176. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  177. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  178. return y;
  179. }
  180. float PS_P010_PQ_Y_709_2020(FragPos frag_in) : TARGET
  181. {
  182. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb * sdr_white_nits_over_maximum;
  183. rgb = rec709_to_rec2020(rgb);
  184. rgb = linear_to_st2084(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_P010_HLG_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_hlg(rgb, hdr_lw);
  194. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  195. y = floor(saturate(y) * 1023. + 0.5) * (64. / 65535.);
  196. return y;
  197. }
  198. float PS_P010_SRGB_Y(FragPos frag_in) : TARGET
  199. {
  200. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  201. rgb = srgb_linear_to_nonlinear(rgb);
  202. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  203. y = floor(saturate(y) * 1023. + 0.5) * (64. / 65535.);
  204. return y;
  205. }
  206. float PS_P216_PQ_Y_709_2020(FragPos frag_in) : TARGET
  207. {
  208. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb * sdr_white_nits_over_maximum;
  209. rgb = rec709_to_rec2020(rgb);
  210. rgb = linear_to_st2084(rgb);
  211. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  212. return y;
  213. }
  214. float PS_P216_HLG_Y_709_2020(FragPos frag_in) : TARGET
  215. {
  216. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb * sdr_white_nits_over_maximum;
  217. rgb = rec709_to_rec2020(rgb);
  218. rgb = linear_to_hlg(rgb, hdr_lw);
  219. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  220. return y;
  221. }
  222. float PS_P216_SRGB_Y(FragPos frag_in) : TARGET
  223. {
  224. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  225. rgb = srgb_linear_to_nonlinear(rgb);
  226. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  227. return y;
  228. }
  229. float PS_P416_PQ_Y_709_2020(FragPos frag_in) : TARGET
  230. {
  231. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb * sdr_white_nits_over_maximum;
  232. rgb = rec709_to_rec2020(rgb);
  233. rgb = linear_to_st2084(rgb);
  234. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  235. return y;
  236. }
  237. float PS_P416_HLG_Y_709_2020(FragPos frag_in) : TARGET
  238. {
  239. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb * sdr_white_nits_over_maximum;
  240. rgb = rec709_to_rec2020(rgb);
  241. rgb = linear_to_hlg(rgb, hdr_lw);
  242. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  243. return y;
  244. }
  245. float PS_P416_SRGB_Y(FragPos frag_in) : TARGET
  246. {
  247. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  248. rgb = srgb_linear_to_nonlinear(rgb);
  249. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  250. return y;
  251. }
  252. float PS_I010_PQ_Y_709_2020(FragPos frag_in) : TARGET
  253. {
  254. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb * sdr_white_nits_over_maximum;
  255. rgb = rec709_to_rec2020(rgb);
  256. rgb = linear_to_st2084(rgb);
  257. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  258. return y * (1023. / 65535.);
  259. }
  260. float PS_I010_HLG_Y_709_2020(FragPos frag_in) : TARGET
  261. {
  262. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb * sdr_white_nits_over_maximum;
  263. rgb = rec709_to_rec2020(rgb);
  264. rgb = linear_to_hlg(rgb, hdr_lw);
  265. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  266. return y * (1023. / 65535.);
  267. }
  268. float PS_I010_SRGB_Y(FragPos frag_in) : TARGET
  269. {
  270. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  271. rgb = srgb_linear_to_nonlinear(rgb);
  272. float y = dot(color_vec0.xyz, rgb) + color_vec0.w;
  273. return y * (1023. / 65535.);
  274. }
  275. float2 PS_UV_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. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  282. return float2(u, v);
  283. }
  284. float2 PS_P010_PQ_UV_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  285. {
  286. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  287. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  288. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  289. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  290. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  291. rgb = rec709_to_rec2020(rgb);
  292. rgb = linear_to_st2084(rgb);
  293. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  294. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  295. float2 uv = float2(u, v);
  296. uv = floor(saturate(uv) * 1023. + 0.5) * (64. / 65535.);
  297. return uv;
  298. }
  299. float2 PS_P010_HLG_UV_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  300. {
  301. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  302. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  303. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  304. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  305. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  306. rgb = rec709_to_rec2020(rgb);
  307. rgb = linear_to_hlg(rgb, hdr_lw);
  308. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  309. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  310. float2 uv = float2(u, v);
  311. uv = floor(saturate(uv) * 1023. + 0.5) * (64. / 65535.);
  312. return uv;
  313. }
  314. float2 PS_P010_SRGB_UV_Wide(FragTexWide frag_in) : TARGET
  315. {
  316. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  317. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  318. float3 rgb = (rgb_left + rgb_right) * 0.5;
  319. rgb = srgb_linear_to_nonlinear(rgb);
  320. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  321. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  322. float2 uv = float2(u, v);
  323. uv = floor(saturate(uv) * 1023. + 0.5) * (64. / 65535.);
  324. return uv;
  325. }
  326. float2 PS_P216_PQ_UV_709_2020_Wide(FragTexWide frag_in) : TARGET
  327. {
  328. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  329. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  330. float3 rgb = (rgb_left + rgb_right) * (0.5 * sdr_white_nits_over_maximum);
  331. rgb = rec709_to_rec2020(rgb);
  332. rgb = linear_to_st2084(rgb);
  333. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  334. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  335. float2 uv = float2(u, v);
  336. return uv;
  337. }
  338. float2 PS_P216_HLG_UV_709_2020_Wide(FragTexWide frag_in) : TARGET
  339. {
  340. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  341. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  342. float3 rgb = (rgb_left + rgb_right) * (0.5 * sdr_white_nits_over_maximum);
  343. rgb = rec709_to_rec2020(rgb);
  344. rgb = linear_to_hlg(rgb, hdr_lw);
  345. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  346. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  347. float2 uv = float2(u, v);
  348. return uv;
  349. }
  350. float2 PS_P216_SRGB_UV_Wide(FragTexWide frag_in) : TARGET
  351. {
  352. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  353. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  354. float3 rgb = (rgb_left + rgb_right) * 0.5;
  355. rgb = srgb_linear_to_nonlinear(rgb);
  356. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  357. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  358. float2 uv = float2(u, v);
  359. return uv;
  360. }
  361. float2 PS_P416_PQ_UV_709_2020(FragPos frag_in) : TARGET
  362. {
  363. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  364. rgb = rec709_to_rec2020(rgb);
  365. rgb = linear_to_st2084(rgb);
  366. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  367. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  368. float2 uv = float2(u, v);
  369. return uv;
  370. }
  371. float2 PS_P416_HLG_UV_709_2020(FragPos frag_in) : TARGET
  372. {
  373. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  374. rgb = rec709_to_rec2020(rgb);
  375. rgb = linear_to_hlg(rgb, hdr_lw);
  376. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  377. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  378. float2 uv = float2(u, v);
  379. return uv;
  380. }
  381. float2 PS_P416_SRGB_UV(FragPos frag_in) : TARGET
  382. {
  383. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  384. rgb = srgb_linear_to_nonlinear(rgb);
  385. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  386. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  387. float2 uv = float2(u, v);
  388. return uv;
  389. }
  390. float PS_U(FragPos frag_in) : TARGET
  391. {
  392. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  393. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  394. return u;
  395. }
  396. float PS_V(FragPos frag_in) : TARGET
  397. {
  398. float3 rgb = image.Load(int3(frag_in.pos.xy, 0)).rgb;
  399. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  400. return v;
  401. }
  402. float PS_U_Wide(FragTexWide frag_in) : TARGET
  403. {
  404. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  405. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  406. float3 rgb = (rgb_left + rgb_right) * 0.5;
  407. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  408. return u;
  409. }
  410. float PS_V_Wide(FragTexWide frag_in) : TARGET
  411. {
  412. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  413. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  414. float3 rgb = (rgb_left + rgb_right) * 0.5;
  415. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  416. return v;
  417. }
  418. float PS_I010_PQ_U_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  419. {
  420. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  421. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  422. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  423. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  424. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  425. rgb = rec709_to_rec2020(rgb);
  426. rgb = linear_to_st2084(rgb);
  427. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  428. return u * (1023. / 65535.);
  429. }
  430. float PS_I010_HLG_U_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  431. {
  432. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  433. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  434. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  435. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  436. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  437. rgb = rec709_to_rec2020(rgb);
  438. rgb = linear_to_hlg(rgb, hdr_lw);
  439. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  440. return u * (1023. / 65535.);
  441. }
  442. float PS_I010_SRGB_U_Wide(FragTexWide frag_in) : TARGET
  443. {
  444. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  445. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  446. float3 rgb = (rgb_left + rgb_right) * 0.5;
  447. rgb = srgb_linear_to_nonlinear(rgb);
  448. float u = dot(color_vec1.xyz, rgb) + color_vec1.w;
  449. return u * (1023. / 65535.);
  450. }
  451. float PS_I010_PQ_V_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  452. {
  453. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  454. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  455. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  456. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  457. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  458. rgb = rec709_to_rec2020(rgb);
  459. rgb = linear_to_st2084(rgb);
  460. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  461. return v * (1023. / 65535.);
  462. }
  463. float PS_I010_HLG_V_709_2020_WideWide(FragTexWideWide frag_in) : TARGET
  464. {
  465. float3 rgb_topleft = image.Sample(def_sampler, frag_in.uuvv.xz).rgb;
  466. float3 rgb_topright = image.Sample(def_sampler, frag_in.uuvv.yz).rgb;
  467. float3 rgb_bottomleft = image.Sample(def_sampler, frag_in.uuvv.xw).rgb;
  468. float3 rgb_bottomright = image.Sample(def_sampler, frag_in.uuvv.yw).rgb;
  469. float3 rgb = (rgb_topleft + rgb_topright + rgb_bottomleft + rgb_bottomright) * (0.25 * sdr_white_nits_over_maximum);
  470. rgb = rec709_to_rec2020(rgb);
  471. rgb = linear_to_hlg(rgb, hdr_lw);
  472. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  473. return v * (1023. / 65535.);
  474. }
  475. float PS_I010_SRGB_V_Wide(FragTexWide frag_in) : TARGET
  476. {
  477. float3 rgb_left = image.Sample(def_sampler, frag_in.uuv.xz).rgb;
  478. float3 rgb_right = image.Sample(def_sampler, frag_in.uuv.yz).rgb;
  479. float3 rgb = (rgb_left + rgb_right) * 0.5;
  480. rgb = srgb_linear_to_nonlinear(rgb);
  481. float v = dot(color_vec2.xyz, rgb) + color_vec2.w;
  482. return v * (1023. / 65535.);
  483. }
  484. float3 YUV_to_RGB(float3 yuv)
  485. {
  486. yuv = clamp(yuv, color_range_min, color_range_max);
  487. float r = dot(color_vec0.xyz, yuv) + color_vec0.w;
  488. float g = dot(color_vec1.xyz, yuv) + color_vec1.w;
  489. float b = dot(color_vec2.xyz, yuv) + color_vec2.w;
  490. return float3(r, g, b);
  491. }
  492. float3 PSUYVY_Reverse(FragTexTex frag_in) : TARGET
  493. {
  494. float2 y01 = image.Load(int3(frag_in.uvuv.xy, 0)).yw;
  495. float2 cbcr = image.Sample(def_sampler, frag_in.uvuv.zw, 0).zx;
  496. float leftover = frac(frag_in.uvuv.x);
  497. float y = (leftover < 0.5) ? y01.x : y01.y;
  498. float3 yuv = float3(y, cbcr);
  499. float3 rgb = YUV_to_RGB(yuv);
  500. return rgb;
  501. }
  502. float3 PSYUY2_Reverse(FragTexTex frag_in) : TARGET
  503. {
  504. float2 y01 = image.Load(int3(frag_in.uvuv.xy, 0)).zx;
  505. float2 cbcr = image.Sample(def_sampler, frag_in.uvuv.zw, 0).yw;
  506. float leftover = frac(frag_in.uvuv.x);
  507. float y = (leftover < 0.5) ? y01.x : y01.y;
  508. float3 yuv = float3(y, cbcr);
  509. float3 rgb = YUV_to_RGB(yuv);
  510. return rgb;
  511. }
  512. float4 PSYUY2_PQ_Reverse(FragTexTex frag_in) : TARGET
  513. {
  514. float2 y01 = image.Load(int3(frag_in.uvuv.xy, 0)).zx;
  515. float2 cbcr = image.Sample(def_sampler, frag_in.uvuv.zw, 0).yw;
  516. float leftover = frac(frag_in.uvuv.x);
  517. float y = (leftover < 0.5) ? y01.x : y01.y;
  518. float3 yuv = float3(y, cbcr);
  519. float3 pq = YUV_to_RGB(yuv);
  520. float3 hdr2020 = st2084_to_linear_eetf(pq, hdr_lw, hdr_lmax) * maximum_over_sdr_white_nits;
  521. float3 rgb = rec2020_to_rec709(hdr2020);
  522. return float4(rgb, 1.);
  523. }
  524. float4 PSYUY2_HLG_Reverse(FragTexTex frag_in) : TARGET
  525. {
  526. float2 y01 = image.Load(int3(frag_in.uvuv.xy, 0)).zx;
  527. float2 cbcr = image.Sample(def_sampler, frag_in.uvuv.zw, 0).yw;
  528. float leftover = frac(frag_in.uvuv.x);
  529. float y = (leftover < 0.5) ? y01.x : y01.y;
  530. float3 yuv = float3(y, cbcr);
  531. float3 hlg = YUV_to_RGB(yuv);
  532. float3 hdr2020 = hlg_to_linear(hlg, hlg_exponent) * maximum_over_sdr_white_nits;
  533. float3 rgb = rec2020_to_rec709(hdr2020);
  534. return float4(rgb, 1.);
  535. }
  536. float3 PSYVYU_Reverse(FragTexTex frag_in) : TARGET
  537. {
  538. float2 y01 = image.Load(int3(frag_in.uvuv.xy, 0)).zx;
  539. float2 cbcr = image.Sample(def_sampler, frag_in.uvuv.zw, 0).wy;
  540. float leftover = frac(frag_in.uvuv.x);
  541. float y = (leftover < 0.5) ? y01.x : y01.y;
  542. float3 yuv = float3(y, cbcr);
  543. float3 rgb = YUV_to_RGB(yuv);
  544. return rgb;
  545. }
  546. float3 PSPlanar420_Reverse(VertTexPos frag_in) : TARGET
  547. {
  548. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  549. float cb = image1.Sample(def_sampler, frag_in.uv).x;
  550. float cr = image2.Sample(def_sampler, frag_in.uv).x;
  551. float3 yuv = float3(y, cb, cr);
  552. float3 rgb = YUV_to_RGB(yuv);
  553. return rgb;
  554. }
  555. float4 PSPlanar420_PQ_Reverse(VertTexPos frag_in) : TARGET
  556. {
  557. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  558. float cb = image1.Sample(def_sampler, frag_in.uv).x;
  559. float cr = image2.Sample(def_sampler, frag_in.uv).x;
  560. float3 yuv = float3(y, cb, cr);
  561. float3 pq = YUV_to_RGB(yuv);
  562. float3 hdr2020 = st2084_to_linear_eetf(pq, hdr_lw, hdr_lmax) * maximum_over_sdr_white_nits;
  563. float3 rgb = rec2020_to_rec709(hdr2020);
  564. return float4(rgb, 1.);
  565. }
  566. float4 PSPlanar420_HLG_Reverse(VertTexPos frag_in) : TARGET
  567. {
  568. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  569. float cb = image1.Sample(def_sampler, frag_in.uv).x;
  570. float cr = image2.Sample(def_sampler, frag_in.uv).x;
  571. float3 yuv = float3(y, cb, cr);
  572. float3 hlg = YUV_to_RGB(yuv);
  573. float3 hdr2020 = hlg_to_linear(hlg, hlg_exponent) * maximum_over_sdr_white_nits;
  574. float3 rgb = rec2020_to_rec709(hdr2020);
  575. return float4(rgb, 1.);
  576. }
  577. float4 PSPlanar420A_Reverse(VertTexPos frag_in) : TARGET
  578. {
  579. int3 xy0_luma = int3(frag_in.pos.xy, 0);
  580. float y = image.Load(xy0_luma).x;
  581. float alpha = image3.Load(xy0_luma).x;
  582. float cb = image1.Sample(def_sampler, frag_in.uv).x;
  583. float cr = image2.Sample(def_sampler, frag_in.uv).x;
  584. float3 yuv = float3(y, cb, cr);
  585. float4 rgba = float4(YUV_to_RGB(yuv), alpha);
  586. return rgba;
  587. }
  588. float3 PSPlanar422_Reverse(VertTexPos frag_in) : TARGET
  589. {
  590. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  591. float cb = image1.Sample(def_sampler, frag_in.uv).x;
  592. float cr = image2.Sample(def_sampler, frag_in.uv).x;
  593. float3 yuv = float3(y, cb, cr);
  594. float3 rgb = YUV_to_RGB(yuv);
  595. return rgb;
  596. }
  597. float4 PSPlanar422_10LE_Reverse(VertTexPos frag_in) : TARGET
  598. {
  599. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  600. float cb = image1.Sample(def_sampler, frag_in.uv).x;
  601. float cr = image2.Sample(def_sampler, frag_in.uv).x;
  602. float3 yuv = float3(y, cb, cr);
  603. yuv *= 65535. / 1023.;
  604. float3 rgb = YUV_to_RGB(yuv);
  605. rgb = srgb_nonlinear_to_linear(rgb);
  606. return float4(rgb, 1.);
  607. }
  608. float4 PSPlanar422_10LE_PQ_Reverse(VertTexPos frag_in) : TARGET
  609. {
  610. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  611. float cb = image1.Sample(def_sampler, frag_in.uv).x;
  612. float cr = image2.Sample(def_sampler, frag_in.uv).x;
  613. float3 yuv = float3(y, cb, cr);
  614. yuv *= 65535. / 1023.;
  615. float3 pq = YUV_to_RGB(yuv);
  616. float3 hdr2020 = st2084_to_linear_eetf(pq, hdr_lw, hdr_lmax) * maximum_over_sdr_white_nits;
  617. float3 rgb = rec2020_to_rec709(hdr2020);
  618. return float4(rgb, 1.);
  619. }
  620. float4 PSPlanar422_10LE_HLG_Reverse(VertTexPos frag_in) : TARGET
  621. {
  622. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  623. float cb = image1.Sample(def_sampler, frag_in.uv).x;
  624. float cr = image2.Sample(def_sampler, frag_in.uv).x;
  625. float3 yuv = float3(y, cb, cr);
  626. yuv *= 65535. / 1023.;
  627. float3 hlg = YUV_to_RGB(yuv);
  628. float3 hdr2020 = hlg_to_linear(hlg, hlg_exponent) * maximum_over_sdr_white_nits;
  629. float3 rgb = rec2020_to_rec709(hdr2020);
  630. return float4(rgb, 1.);
  631. }
  632. float4 PSPlanar422A_Reverse(VertTexPos frag_in) : TARGET
  633. {
  634. int3 xy0_luma = int3(frag_in.pos.xy, 0);
  635. float y = image.Load(xy0_luma).x;
  636. float alpha = image3.Load(xy0_luma).x;
  637. float cb = image1.Sample(def_sampler, frag_in.uv).x;
  638. float cr = image2.Sample(def_sampler, frag_in.uv).x;
  639. float3 yuv = float3(y, cb, cr);
  640. float4 rgba = float4(YUV_to_RGB(yuv), alpha);
  641. return rgba;
  642. }
  643. float3 PSPlanar444_Reverse(FragPos frag_in) : TARGET
  644. {
  645. int3 xy0 = int3(frag_in.pos.xy, 0);
  646. float y = image.Load(xy0).x;
  647. float cb = image1.Load(xy0).x;
  648. float cr = image2.Load(xy0).x;
  649. float3 yuv = float3(y, cb, cr);
  650. float3 rgb = YUV_to_RGB(yuv);
  651. return rgb;
  652. }
  653. float4 PSPlanar444_12LE_Reverse(FragPos frag_in) : TARGET
  654. {
  655. int3 xy0 = int3(frag_in.pos.xy, 0);
  656. float y = image.Load(xy0).x;
  657. float cb = image1.Load(xy0).x;
  658. float cr = image2.Load(xy0).x;
  659. float3 yuv = float3(y, cb, cr);
  660. yuv *= 65535. / 4095.;
  661. float3 rgb = YUV_to_RGB(yuv);
  662. rgb = srgb_nonlinear_to_linear(rgb);
  663. return float4(rgb, 1.);
  664. }
  665. float4 PSPlanar444_12LE_PQ_Reverse(FragPos frag_in) : TARGET
  666. {
  667. int3 xy0 = int3(frag_in.pos.xy, 0);
  668. float y = image.Load(xy0).x;
  669. float cb = image1.Load(xy0).x;
  670. float cr = image2.Load(xy0).x;
  671. float3 yuv = float3(y, cb, cr);
  672. yuv *= 65535. / 4095;
  673. float3 pq = YUV_to_RGB(yuv);
  674. float3 hdr2020 = st2084_to_linear_eetf(pq, hdr_lw, hdr_lmax) * maximum_over_sdr_white_nits;
  675. float3 rgb = rec2020_to_rec709(hdr2020);
  676. return float4(rgb, 1.);
  677. }
  678. float4 PSPlanar444_12LE_HLG_Reverse(FragPos frag_in) : TARGET
  679. {
  680. int3 xy0 = int3(frag_in.pos.xy, 0);
  681. float y = image.Load(xy0).x;
  682. float cb = image1.Load(xy0).x;
  683. float cr = image2.Load(xy0).x;
  684. float3 yuv = float3(y, cb, cr);
  685. yuv *= 65535. / 4095;
  686. float3 hlg = YUV_to_RGB(yuv);
  687. float3 hdr2020 = hlg_to_linear(hlg, hlg_exponent) * maximum_over_sdr_white_nits;
  688. float3 rgb = rec2020_to_rec709(hdr2020);
  689. return float4(rgb, 1.);
  690. }
  691. float4 PSPlanar444A_Reverse(FragPos frag_in) : TARGET
  692. {
  693. int3 xy0 = int3(frag_in.pos.xy, 0);
  694. float y = image.Load(xy0).x;
  695. float cb = image1.Load(xy0).x;
  696. float cr = image2.Load(xy0).x;
  697. float alpha = image3.Load(xy0).x;
  698. float3 yuv = float3(y, cb, cr);
  699. float4 rgba = float4(YUV_to_RGB(yuv), alpha);
  700. return rgba;
  701. }
  702. float4 PSPlanar444A_12LE_Reverse(FragPos frag_in) : TARGET
  703. {
  704. int3 xy0 = int3(frag_in.pos.xy, 0);
  705. float y = image.Load(xy0).x;
  706. float cb = image1.Load(xy0).x;
  707. float cr = image2.Load(xy0).x;
  708. float alpha = image3.Load(xy0).x * 16.;
  709. float3 yuv = float3(y, cb, cr);
  710. yuv *= 65535. / 4095.;
  711. float3 rgb = YUV_to_RGB(yuv);
  712. rgb = srgb_nonlinear_to_linear(rgb);
  713. return float4(rgb, alpha);
  714. }
  715. float4 PSAYUV_Reverse(FragPos frag_in) : TARGET
  716. {
  717. float4 yuva = image.Load(int3(frag_in.pos.xy, 0));
  718. float4 rgba = float4(YUV_to_RGB(yuva.xyz), yuva.a);
  719. return rgba;
  720. }
  721. float3 PSNV12_Reverse(VertTexPos frag_in) : TARGET
  722. {
  723. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  724. float2 cbcr = image1.Sample(def_sampler, frag_in.uv).xy;
  725. float3 yuv = float3(y, cbcr);
  726. float3 rgb = YUV_to_RGB(yuv);
  727. return rgb;
  728. }
  729. float4 PSNV12_PQ_Reverse(VertTexPos frag_in) : TARGET
  730. {
  731. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  732. float2 cbcr = image1.Sample(def_sampler, frag_in.uv).xy;
  733. float3 yuv = float3(y, cbcr);
  734. float3 pq = YUV_to_RGB(yuv);
  735. float3 hdr2020 = st2084_to_linear_eetf(pq, hdr_lw, hdr_lmax) * maximum_over_sdr_white_nits;
  736. float3 rgb = rec2020_to_rec709(hdr2020);
  737. return float4(rgb, 1.);
  738. }
  739. float4 PSNV12_HLG_Reverse(VertTexPos frag_in) : TARGET
  740. {
  741. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  742. float2 cbcr = image1.Sample(def_sampler, frag_in.uv).xy;
  743. float3 yuv = float3(y, cbcr);
  744. float3 hlg = YUV_to_RGB(yuv);
  745. float3 hdr2020 = hlg_to_linear(hlg, hlg_exponent) * maximum_over_sdr_white_nits;
  746. float3 rgb = rec2020_to_rec709(hdr2020);
  747. return float4(rgb, 1.);
  748. }
  749. float4 PSI010_SRGB_Reverse(VertTexPos frag_in) : TARGET
  750. {
  751. float ratio = 65535. / 1023.;
  752. float y = image.Load(int3(frag_in.pos.xy, 0)).x * ratio;
  753. float cb = image1.Sample(def_sampler, frag_in.uv).x * ratio;
  754. float cr = image2.Sample(def_sampler, frag_in.uv).x * ratio;
  755. float3 yuv = float3(y, cb, cr);
  756. float3 rgb = YUV_to_RGB(yuv);
  757. rgb = srgb_nonlinear_to_linear(rgb);
  758. return float4(rgb, 1.);
  759. }
  760. float4 PSI010_PQ_2020_709_Reverse(VertTexPos frag_in) : TARGET
  761. {
  762. float ratio = 65535. / 1023.;
  763. float y = image.Load(int3(frag_in.pos.xy, 0)).x * ratio;
  764. float cb = image1.Sample(def_sampler, frag_in.uv).x * ratio;
  765. float cr = image2.Sample(def_sampler, frag_in.uv).x * ratio;
  766. float3 yuv = float3(y, cb, cr);
  767. float3 pq = YUV_to_RGB(yuv);
  768. float3 hdr2020 = st2084_to_linear_eetf(pq, hdr_lw, hdr_lmax) * maximum_over_sdr_white_nits;
  769. float3 rgb = rec2020_to_rec709(hdr2020);
  770. return float4(rgb, 1.);
  771. }
  772. float4 PSI010_HLG_2020_709_Reverse(VertTexPos frag_in) : TARGET
  773. {
  774. float ratio = 65535. / 1023.;
  775. float y = image.Load(int3(frag_in.pos.xy, 0)).x * ratio;
  776. float cb = image1.Sample(def_sampler, frag_in.uv).x * ratio;
  777. float cr = image2.Sample(def_sampler, frag_in.uv).x * ratio;
  778. float3 yuv = float3(y, cb, cr);
  779. float3 hlg = YUV_to_RGB(yuv);
  780. float3 hdr2020 = hlg_to_linear(hlg, hlg_exponent) * maximum_over_sdr_white_nits;
  781. float3 rgb = rec2020_to_rec709(hdr2020);
  782. return float4(rgb, 1.);
  783. }
  784. float4 PSP010_SRGB_Reverse(VertTexPos frag_in) : TARGET
  785. {
  786. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  787. float2 cbcr = image1.Sample(def_sampler, frag_in.uv).xy;
  788. float3 yuv_65535 = floor(float3(y, cbcr) * 65535. + 0.5);
  789. float3 yuv_1023 = floor(yuv_65535 * 0.015625);
  790. float3 yuv = yuv_1023 / 1023.;
  791. float3 rgb = YUV_to_RGB(yuv);
  792. rgb = srgb_nonlinear_to_linear(rgb);
  793. return float4(rgb, 1.);
  794. }
  795. float4 PSP010_PQ_2020_709_Reverse(VertTexPos frag_in) : TARGET
  796. {
  797. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  798. float2 cbcr = image1.Sample(def_sampler, frag_in.uv).xy;
  799. float3 yuv_65535 = floor(float3(y, cbcr) * 65535. + 0.5);
  800. float3 yuv_1023 = floor(yuv_65535 * 0.015625);
  801. float3 yuv = yuv_1023 / 1023.;
  802. float3 pq = YUV_to_RGB(yuv);
  803. float3 hdr2020 = st2084_to_linear_eetf(pq, hdr_lw, hdr_lmax) * maximum_over_sdr_white_nits;
  804. float3 rgb = rec2020_to_rec709(hdr2020);
  805. return float4(rgb, 1.);
  806. }
  807. float4 PSP010_HLG_2020_709_Reverse(VertTexPos frag_in) : TARGET
  808. {
  809. float y = image.Load(int3(frag_in.pos.xy, 0)).x;
  810. float2 cbcr = image1.Sample(def_sampler, frag_in.uv).xy;
  811. float3 yuv_65535 = floor(float3(y, cbcr) * 65535. + 0.5);
  812. float3 yuv_1023 = floor(yuv_65535 * 0.015625);
  813. float3 yuv = yuv_1023 / 1023.;
  814. float3 hlg = YUV_to_RGB(yuv);
  815. float3 hdr2020 = hlg_to_linear(hlg, hlg_exponent) * maximum_over_sdr_white_nits;
  816. float3 rgb = rec2020_to_rec709(hdr2020);
  817. return float4(rgb, 1.);
  818. }
  819. float3 PSY800_Limited(FragPos frag_in) : TARGET
  820. {
  821. float limited = image.Load(int3(frag_in.pos.xy, 0)).x;
  822. float full = (255.0 / 219.0) * limited - (16.0 / 219.0);
  823. return float3(full, full, full);
  824. }
  825. float3 PSY800_Full(FragPos frag_in) : TARGET
  826. {
  827. float3 full = image.Load(int3(frag_in.pos.xy, 0)).xxx;
  828. return full;
  829. }
  830. float4 PSRGB_Limited(FragPos frag_in) : TARGET
  831. {
  832. float4 rgba = image.Load(int3(frag_in.pos.xy, 0));
  833. rgba.rgb = (255.0 / 219.0) * rgba.rgb - (16.0 / 219.0);
  834. return rgba;
  835. }
  836. float3 PSBGR3_Limited(FragPos frag_in) : TARGET
  837. {
  838. float x = frag_in.pos.x * 3.0;
  839. float y = frag_in.pos.y;
  840. float b = image.Load(int3(x - 1.0, y, 0)).x;
  841. float g = image.Load(int3(x, y, 0)).x;
  842. float r = image.Load(int3(x + 1.0, y, 0)).x;
  843. float3 rgb = float3(r, g, b);
  844. rgb = (255.0 / 219.0) * rgb - (16.0 / 219.0);
  845. return rgb;
  846. }
  847. float3 PSBGR3_Full(FragPos frag_in) : TARGET
  848. {
  849. float x = frag_in.pos.x * 3.0;
  850. float y = frag_in.pos.y;
  851. float b = image.Load(int3(x - 1.0, y, 0)).x;
  852. float g = image.Load(int3(x, y, 0)).x;
  853. float r = image.Load(int3(x + 1.0, y, 0)).x;
  854. float3 rgb = float3(r, g, b);
  855. return rgb;
  856. }
  857. technique Planar_Y
  858. {
  859. pass
  860. {
  861. vertex_shader = VSPos(id);
  862. pixel_shader = PS_Y(frag_in);
  863. }
  864. }
  865. technique Planar_U
  866. {
  867. pass
  868. {
  869. vertex_shader = VSPos(id);
  870. pixel_shader = PS_U(frag_in);
  871. }
  872. }
  873. technique Planar_V
  874. {
  875. pass
  876. {
  877. vertex_shader = VSPos(id);
  878. pixel_shader = PS_V(frag_in);
  879. }
  880. }
  881. technique Planar_U_Left
  882. {
  883. pass
  884. {
  885. vertex_shader = VSTexPos_Left(id);
  886. pixel_shader = PS_U_Wide(frag_in);
  887. }
  888. }
  889. technique Planar_V_Left
  890. {
  891. pass
  892. {
  893. vertex_shader = VSTexPos_Left(id);
  894. pixel_shader = PS_V_Wide(frag_in);
  895. }
  896. }
  897. technique NV12_Y
  898. {
  899. pass
  900. {
  901. vertex_shader = VSPos(id);
  902. pixel_shader = PS_Y(frag_in);
  903. }
  904. }
  905. technique NV12_UV
  906. {
  907. pass
  908. {
  909. vertex_shader = VSTexPos_Left(id);
  910. pixel_shader = PS_UV_Wide(frag_in);
  911. }
  912. }
  913. technique I010_PQ_Y
  914. {
  915. pass
  916. {
  917. vertex_shader = VSPos(id);
  918. pixel_shader = PS_I010_PQ_Y_709_2020(frag_in);
  919. }
  920. }
  921. technique I010_HLG_Y
  922. {
  923. pass
  924. {
  925. vertex_shader = VSPos(id);
  926. pixel_shader = PS_I010_HLG_Y_709_2020(frag_in);
  927. }
  928. }
  929. technique I010_SRGB_Y
  930. {
  931. pass
  932. {
  933. vertex_shader = VSPos(id);
  934. pixel_shader = PS_I010_SRGB_Y(frag_in);
  935. }
  936. }
  937. technique I010_PQ_U
  938. {
  939. pass
  940. {
  941. vertex_shader = VSTexPos_TopLeft(id);
  942. pixel_shader = PS_I010_PQ_U_709_2020_WideWide(frag_in);
  943. }
  944. }
  945. technique I010_HLG_U
  946. {
  947. pass
  948. {
  949. vertex_shader = VSTexPos_TopLeft(id);
  950. pixel_shader = PS_I010_HLG_U_709_2020_WideWide(frag_in);
  951. }
  952. }
  953. technique I010_SRGB_U
  954. {
  955. pass
  956. {
  957. vertex_shader = VSTexPos_Left(id);
  958. pixel_shader = PS_I010_SRGB_U_Wide(frag_in);
  959. }
  960. }
  961. technique I010_PQ_V
  962. {
  963. pass
  964. {
  965. vertex_shader = VSTexPos_TopLeft(id);
  966. pixel_shader = PS_I010_PQ_V_709_2020_WideWide(frag_in);
  967. }
  968. }
  969. technique I010_HLG_V
  970. {
  971. pass
  972. {
  973. vertex_shader = VSTexPos_TopLeft(id);
  974. pixel_shader = PS_I010_HLG_V_709_2020_WideWide(frag_in);
  975. }
  976. }
  977. technique I010_SRGB_V
  978. {
  979. pass
  980. {
  981. vertex_shader = VSTexPos_Left(id);
  982. pixel_shader = PS_I010_SRGB_V_Wide(frag_in);
  983. }
  984. }
  985. technique P010_PQ_Y
  986. {
  987. pass
  988. {
  989. vertex_shader = VSPos(id);
  990. pixel_shader = PS_P010_PQ_Y_709_2020(frag_in);
  991. }
  992. }
  993. technique P010_HLG_Y
  994. {
  995. pass
  996. {
  997. vertex_shader = VSPos(id);
  998. pixel_shader = PS_P010_HLG_Y_709_2020(frag_in);
  999. }
  1000. }
  1001. technique P010_SRGB_Y
  1002. {
  1003. pass
  1004. {
  1005. vertex_shader = VSPos(id);
  1006. pixel_shader = PS_P010_SRGB_Y(frag_in);
  1007. }
  1008. }
  1009. technique P010_PQ_UV
  1010. {
  1011. pass
  1012. {
  1013. vertex_shader = VSTexPos_TopLeft(id);
  1014. pixel_shader = PS_P010_PQ_UV_709_2020_WideWide(frag_in);
  1015. }
  1016. }
  1017. technique P010_HLG_UV
  1018. {
  1019. pass
  1020. {
  1021. vertex_shader = VSTexPos_TopLeft(id);
  1022. pixel_shader = PS_P010_HLG_UV_709_2020_WideWide(frag_in);
  1023. }
  1024. }
  1025. technique P010_SRGB_UV
  1026. {
  1027. pass
  1028. {
  1029. vertex_shader = VSTexPos_Left(id);
  1030. pixel_shader = PS_P010_SRGB_UV_Wide(frag_in);
  1031. }
  1032. }
  1033. technique P216_PQ_Y
  1034. {
  1035. pass
  1036. {
  1037. vertex_shader = VSPos(id);
  1038. pixel_shader = PS_P216_PQ_Y_709_2020(frag_in);
  1039. }
  1040. }
  1041. technique P216_HLG_Y
  1042. {
  1043. pass
  1044. {
  1045. vertex_shader = VSPos(id);
  1046. pixel_shader = PS_P216_HLG_Y_709_2020(frag_in);
  1047. }
  1048. }
  1049. technique P216_SRGB_Y
  1050. {
  1051. pass
  1052. {
  1053. vertex_shader = VSPos(id);
  1054. pixel_shader = PS_P216_SRGB_Y(frag_in);
  1055. }
  1056. }
  1057. technique P216_PQ_UV
  1058. {
  1059. pass
  1060. {
  1061. vertex_shader = VSTexPos_Left(id);
  1062. pixel_shader = PS_P216_PQ_UV_709_2020_Wide(frag_in);
  1063. }
  1064. }
  1065. technique P216_HLG_UV
  1066. {
  1067. pass
  1068. {
  1069. vertex_shader = VSTexPos_Left(id);
  1070. pixel_shader = PS_P216_HLG_UV_709_2020_Wide(frag_in);
  1071. }
  1072. }
  1073. technique P216_SRGB_UV
  1074. {
  1075. pass
  1076. {
  1077. vertex_shader = VSTexPos_Left(id);
  1078. pixel_shader = PS_P216_SRGB_UV_Wide(frag_in);
  1079. }
  1080. }
  1081. technique P416_PQ_Y
  1082. {
  1083. pass
  1084. {
  1085. vertex_shader = VSPos(id);
  1086. pixel_shader = PS_P416_PQ_Y_709_2020(frag_in);
  1087. }
  1088. }
  1089. technique P416_HLG_Y
  1090. {
  1091. pass
  1092. {
  1093. vertex_shader = VSPos(id);
  1094. pixel_shader = PS_P416_HLG_Y_709_2020(frag_in);
  1095. }
  1096. }
  1097. technique P416_SRGB_Y
  1098. {
  1099. pass
  1100. {
  1101. vertex_shader = VSPos(id);
  1102. pixel_shader = PS_P416_SRGB_Y(frag_in);
  1103. }
  1104. }
  1105. technique P416_PQ_UV
  1106. {
  1107. pass
  1108. {
  1109. vertex_shader = VSPos(id);
  1110. pixel_shader = PS_P416_PQ_UV_709_2020(frag_in);
  1111. }
  1112. }
  1113. technique P416_HLG_UV
  1114. {
  1115. pass
  1116. {
  1117. vertex_shader = VSPos(id);
  1118. pixel_shader = PS_P416_HLG_UV_709_2020(frag_in);
  1119. }
  1120. }
  1121. technique P416_SRGB_UV
  1122. {
  1123. pass
  1124. {
  1125. vertex_shader = VSPos(id);
  1126. pixel_shader = PS_P416_SRGB_UV(frag_in);
  1127. }
  1128. }
  1129. technique UYVY_Reverse
  1130. {
  1131. pass
  1132. {
  1133. vertex_shader = VSPacked422Left_Reverse(id);
  1134. pixel_shader = PSUYVY_Reverse(frag_in);
  1135. }
  1136. }
  1137. technique YUY2_Reverse
  1138. {
  1139. pass
  1140. {
  1141. vertex_shader = VSPacked422Left_Reverse(id);
  1142. pixel_shader = PSYUY2_Reverse(frag_in);
  1143. }
  1144. }
  1145. technique YUY2_PQ_Reverse
  1146. {
  1147. pass
  1148. {
  1149. vertex_shader = VSPacked422Left_Reverse(id);
  1150. pixel_shader = PSYUY2_PQ_Reverse(frag_in);
  1151. }
  1152. }
  1153. technique YUY2_HLG_Reverse
  1154. {
  1155. pass
  1156. {
  1157. vertex_shader = VSPacked422Left_Reverse(id);
  1158. pixel_shader = PSYUY2_HLG_Reverse(frag_in);
  1159. }
  1160. }
  1161. technique YVYU_Reverse
  1162. {
  1163. pass
  1164. {
  1165. vertex_shader = VSPacked422Left_Reverse(id);
  1166. pixel_shader = PSYVYU_Reverse(frag_in);
  1167. }
  1168. }
  1169. technique I420_Reverse
  1170. {
  1171. pass
  1172. {
  1173. vertex_shader = VS420Left_Reverse(id);
  1174. pixel_shader = PSPlanar420_Reverse(frag_in);
  1175. }
  1176. }
  1177. technique I420_PQ_Reverse
  1178. {
  1179. pass
  1180. {
  1181. vertex_shader = VS420TopLeft_Reverse(id);
  1182. pixel_shader = PSPlanar420_PQ_Reverse(frag_in);
  1183. }
  1184. }
  1185. technique I420_HLG_Reverse
  1186. {
  1187. pass
  1188. {
  1189. vertex_shader = VS420TopLeft_Reverse(id);
  1190. pixel_shader = PSPlanar420_HLG_Reverse(frag_in);
  1191. }
  1192. }
  1193. technique I40A_Reverse
  1194. {
  1195. pass
  1196. {
  1197. vertex_shader = VS420Left_Reverse(id);
  1198. pixel_shader = PSPlanar420A_Reverse(frag_in);
  1199. }
  1200. }
  1201. technique I422_Reverse
  1202. {
  1203. pass
  1204. {
  1205. vertex_shader = VS422Left_Reverse(id);
  1206. pixel_shader = PSPlanar422_Reverse(frag_in);
  1207. }
  1208. }
  1209. technique I210_Reverse
  1210. {
  1211. pass
  1212. {
  1213. vertex_shader = VS422Left_Reverse(id);
  1214. pixel_shader = PSPlanar422_10LE_Reverse(frag_in);
  1215. }
  1216. }
  1217. technique I210_PQ_Reverse
  1218. {
  1219. pass
  1220. {
  1221. vertex_shader = VS422Left_Reverse(id);
  1222. pixel_shader = PSPlanar422_10LE_PQ_Reverse(frag_in);
  1223. }
  1224. }
  1225. technique I210_HLG_Reverse
  1226. {
  1227. pass
  1228. {
  1229. vertex_shader = VS422Left_Reverse(id);
  1230. pixel_shader = PSPlanar422_10LE_HLG_Reverse(frag_in);
  1231. }
  1232. }
  1233. technique I42A_Reverse
  1234. {
  1235. pass
  1236. {
  1237. vertex_shader = VS422Left_Reverse(id);
  1238. pixel_shader = PSPlanar422A_Reverse(frag_in);
  1239. }
  1240. }
  1241. technique I444_Reverse
  1242. {
  1243. pass
  1244. {
  1245. vertex_shader = VSPos(id);
  1246. pixel_shader = PSPlanar444_Reverse(frag_in);
  1247. }
  1248. }
  1249. technique I412_Reverse
  1250. {
  1251. pass
  1252. {
  1253. vertex_shader = VSPos(id);
  1254. pixel_shader = PSPlanar444_12LE_Reverse(frag_in);
  1255. }
  1256. }
  1257. technique I412_PQ_Reverse
  1258. {
  1259. pass
  1260. {
  1261. vertex_shader = VSPos(id);
  1262. pixel_shader = PSPlanar444_12LE_PQ_Reverse(frag_in);
  1263. }
  1264. }
  1265. technique I412_HLG_Reverse
  1266. {
  1267. pass
  1268. {
  1269. vertex_shader = VSPos(id);
  1270. pixel_shader = PSPlanar444_12LE_HLG_Reverse(frag_in);
  1271. }
  1272. }
  1273. technique YUVA_Reverse
  1274. {
  1275. pass
  1276. {
  1277. vertex_shader = VSPos(id);
  1278. pixel_shader = PSPlanar444A_Reverse(frag_in);
  1279. }
  1280. }
  1281. technique YA2L_Reverse
  1282. {
  1283. pass
  1284. {
  1285. vertex_shader = VSPos(id);
  1286. pixel_shader = PSPlanar444A_12LE_Reverse(frag_in);
  1287. }
  1288. }
  1289. technique AYUV_Reverse
  1290. {
  1291. pass
  1292. {
  1293. vertex_shader = VSPos(id);
  1294. pixel_shader = PSAYUV_Reverse(frag_in);
  1295. }
  1296. }
  1297. technique NV12_Reverse
  1298. {
  1299. pass
  1300. {
  1301. vertex_shader = VS420Left_Reverse(id);
  1302. pixel_shader = PSNV12_Reverse(frag_in);
  1303. }
  1304. }
  1305. technique NV12_PQ_Reverse
  1306. {
  1307. pass
  1308. {
  1309. vertex_shader = VS420TopLeft_Reverse(id);
  1310. pixel_shader = PSNV12_PQ_Reverse(frag_in);
  1311. }
  1312. }
  1313. technique NV12_HLG_Reverse
  1314. {
  1315. pass
  1316. {
  1317. vertex_shader = VS420TopLeft_Reverse(id);
  1318. pixel_shader = PSNV12_HLG_Reverse(frag_in);
  1319. }
  1320. }
  1321. technique I010_SRGB_Reverse
  1322. {
  1323. pass
  1324. {
  1325. vertex_shader = VS420Left_Reverse(id);
  1326. pixel_shader = PSI010_SRGB_Reverse(frag_in);
  1327. }
  1328. }
  1329. technique I010_PQ_2020_709_Reverse
  1330. {
  1331. pass
  1332. {
  1333. vertex_shader = VS420TopLeft_Reverse(id);
  1334. pixel_shader = PSI010_PQ_2020_709_Reverse(frag_in);
  1335. }
  1336. }
  1337. technique I010_HLG_2020_709_Reverse
  1338. {
  1339. pass
  1340. {
  1341. vertex_shader = VS420TopLeft_Reverse(id);
  1342. pixel_shader = PSI010_HLG_2020_709_Reverse(frag_in);
  1343. }
  1344. }
  1345. technique P010_SRGB_Reverse
  1346. {
  1347. pass
  1348. {
  1349. vertex_shader = VS420Left_Reverse(id);
  1350. pixel_shader = PSP010_SRGB_Reverse(frag_in);
  1351. }
  1352. }
  1353. technique P010_PQ_2020_709_Reverse
  1354. {
  1355. pass
  1356. {
  1357. vertex_shader = VS420TopLeft_Reverse(id);
  1358. pixel_shader = PSP010_PQ_2020_709_Reverse(frag_in);
  1359. }
  1360. }
  1361. technique P010_HLG_2020_709_Reverse
  1362. {
  1363. pass
  1364. {
  1365. vertex_shader = VS420TopLeft_Reverse(id);
  1366. pixel_shader = PSP010_HLG_2020_709_Reverse(frag_in);
  1367. }
  1368. }
  1369. technique Y800_Limited
  1370. {
  1371. pass
  1372. {
  1373. vertex_shader = VSPos(id);
  1374. pixel_shader = PSY800_Limited(frag_in);
  1375. }
  1376. }
  1377. technique Y800_Full
  1378. {
  1379. pass
  1380. {
  1381. vertex_shader = VSPos(id);
  1382. pixel_shader = PSY800_Full(frag_in);
  1383. }
  1384. }
  1385. technique RGB_Limited
  1386. {
  1387. pass
  1388. {
  1389. vertex_shader = VSPos(id);
  1390. pixel_shader = PSRGB_Limited(frag_in);
  1391. }
  1392. }
  1393. technique BGR3_Limited
  1394. {
  1395. pass
  1396. {
  1397. vertex_shader = VSPos(id);
  1398. pixel_shader = PSBGR3_Limited(frag_in);
  1399. }
  1400. }
  1401. technique BGR3_Full
  1402. {
  1403. pass
  1404. {
  1405. vertex_shader = VSPos(id);
  1406. pixel_shader = PSBGR3_Full(frag_in);
  1407. }
  1408. }