format_conversion.effect 27 KB

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