default.effect 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #include "color.effect"
  2. uniform float4x4 ViewProj;
  3. uniform texture2d image;
  4. uniform float multiplier;
  5. sampler_state def_sampler {
  6. Filter = Linear;
  7. AddressU = Clamp;
  8. AddressV = Clamp;
  9. };
  10. struct VertInOut {
  11. float4 pos : POSITION;
  12. float2 uv : TEXCOORD0;
  13. };
  14. VertInOut VSDefault(VertInOut vert_in)
  15. {
  16. VertInOut vert_out;
  17. vert_out.pos = mul(float4(vert_in.pos.xyz, 1.0), ViewProj);
  18. vert_out.uv = vert_in.uv;
  19. return vert_out;
  20. }
  21. float4 PSDrawBare(VertInOut vert_in) : TARGET
  22. {
  23. return image.Sample(def_sampler, vert_in.uv);
  24. }
  25. float4 PSDrawAlphaDivide(VertInOut vert_in) : TARGET
  26. {
  27. float4 rgba = image.Sample(def_sampler, vert_in.uv);
  28. rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
  29. return rgba;
  30. }
  31. float4 PSDrawAlphaDivideTonemap(VertInOut vert_in) : TARGET
  32. {
  33. float4 rgba = image.Sample(def_sampler, vert_in.uv);
  34. rgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;
  35. rgba.rgb = rec709_to_rec2020(rgba.rgb);
  36. rgba.rgb = reinhard(rgba.rgb);
  37. rgba.rgb = rec2020_to_rec709(rgba.rgb);
  38. return rgba;
  39. }
  40. float4 PSDrawAlphaDivideR10L(VertInOut vert_in) : TARGET
  41. {
  42. float4 rgba = image.Sample(def_sampler, vert_in.uv);
  43. rgba.rgb *= (rgba.a > 0.) ? (multiplier / rgba.a) : 0.;
  44. rgba.rgb = rec709_to_rec2020(rgba.rgb);
  45. rgba.rgb = linear_to_st2084(rgba.rgb);
  46. uint3 rgb1023 = uint3(mad(rgba.rgb, 1023., .5));
  47. uint b = (rgb1023.b & 0x3Fu) << 2;
  48. uint g = ((rgb1023.b & 0x3C0u) >> 6) | ((rgb1023.g & 0xFu) << 4);
  49. uint r = ((rgb1023.g & 0x3F0u) >> 4) | ((rgb1023.r & 0x3u) << 6);
  50. uint a = ((rgb1023.r & 0x3FCu) >> 2);
  51. return float4(uint4(r, g, b, a)) / 255.;
  52. }
  53. float4 PSDrawNonlinearAlpha(VertInOut vert_in) : TARGET
  54. {
  55. float4 rgba = image.Sample(def_sampler, vert_in.uv);
  56. rgba.rgb = srgb_linear_to_nonlinear(rgba.rgb);
  57. rgba.rgb *= rgba.a;
  58. rgba.rgb = srgb_nonlinear_to_linear(rgba.rgb);
  59. return rgba;
  60. }
  61. float4 PSDrawNonlinearAlphaMultiply(VertInOut vert_in) : TARGET
  62. {
  63. float4 rgba = image.Sample(def_sampler, vert_in.uv);
  64. rgba.rgb = srgb_linear_to_nonlinear(rgba.rgb);
  65. rgba.rgb *= rgba.a;
  66. rgba.rgb = srgb_nonlinear_to_linear(rgba.rgb);
  67. rgba.rgb *= multiplier;
  68. return rgba;
  69. }
  70. float4 PSDrawSrgbDecompress(VertInOut vert_in) : TARGET
  71. {
  72. float4 rgba = image.Sample(def_sampler, vert_in.uv);
  73. rgba.rgb = srgb_nonlinear_to_linear(rgba.rgb);
  74. return rgba;
  75. }
  76. float4 PSDrawSrgbDecompressMultiply(VertInOut vert_in) : TARGET
  77. {
  78. float4 rgba = image.Sample(def_sampler, vert_in.uv);
  79. rgba.rgb = srgb_nonlinear_to_linear(rgba.rgb);
  80. rgba.rgb *= multiplier;
  81. return rgba;
  82. }
  83. float4 PSDrawMultiply(VertInOut vert_in) : TARGET
  84. {
  85. float4 rgba = image.Sample(def_sampler, vert_in.uv);
  86. rgba.rgb *= multiplier;
  87. return rgba;
  88. }
  89. float4 PSDrawTonemap(VertInOut vert_in) : TARGET
  90. {
  91. float4 rgba = image.Sample(def_sampler, vert_in.uv);
  92. rgba.rgb = rec709_to_rec2020(rgba.rgb);
  93. rgba.rgb = reinhard(rgba.rgb);
  94. rgba.rgb = rec2020_to_rec709(rgba.rgb);
  95. return rgba;
  96. }
  97. float4 PSDrawMultiplyTonemap(VertInOut vert_in) : TARGET
  98. {
  99. float4 rgba = image.Sample(def_sampler, vert_in.uv);
  100. rgba.rgb *= multiplier;
  101. rgba.rgb = rec709_to_rec2020(rgba.rgb);
  102. rgba.rgb = reinhard(rgba.rgb);
  103. rgba.rgb = rec2020_to_rec709(rgba.rgb);
  104. return rgba;
  105. }
  106. float4 PSDrawPQ(VertInOut vert_in) : TARGET
  107. {
  108. float4 rgba = image.Sample(def_sampler, vert_in.uv);
  109. rgba.rgb = st2084_to_linear(rgba.rgb) * multiplier;
  110. rgba.rgb = rec2020_to_rec709(rgba.rgb);
  111. return rgba;
  112. }
  113. float4 PSDrawTonemapPQ(VertInOut vert_in) : TARGET
  114. {
  115. float4 rgba = image.Sample(def_sampler, vert_in.uv);
  116. rgba.rgb = st2084_to_linear(rgba.rgb) * multiplier;
  117. rgba.rgb = reinhard(rgba.rgb);
  118. rgba.rgb = rec2020_to_rec709(rgba.rgb);
  119. return rgba;
  120. }
  121. technique Draw
  122. {
  123. pass
  124. {
  125. vertex_shader = VSDefault(vert_in);
  126. pixel_shader = PSDrawBare(vert_in);
  127. }
  128. }
  129. technique DrawAlphaDivide
  130. {
  131. pass
  132. {
  133. vertex_shader = VSDefault(vert_in);
  134. pixel_shader = PSDrawAlphaDivide(vert_in);
  135. }
  136. }
  137. technique DrawAlphaDivideTonemap
  138. {
  139. pass
  140. {
  141. vertex_shader = VSDefault(vert_in);
  142. pixel_shader = PSDrawAlphaDivideTonemap(vert_in);
  143. }
  144. }
  145. technique DrawAlphaDivideR10L
  146. {
  147. pass
  148. {
  149. vertex_shader = VSDefault(vert_in);
  150. pixel_shader = PSDrawAlphaDivideR10L(vert_in);
  151. }
  152. }
  153. technique DrawNonlinearAlpha
  154. {
  155. pass
  156. {
  157. vertex_shader = VSDefault(vert_in);
  158. pixel_shader = PSDrawNonlinearAlpha(vert_in);
  159. }
  160. }
  161. technique DrawNonlinearAlphaMultiply
  162. {
  163. pass
  164. {
  165. vertex_shader = VSDefault(vert_in);
  166. pixel_shader = PSDrawNonlinearAlphaMultiply(vert_in);
  167. }
  168. }
  169. technique DrawSrgbDecompress
  170. {
  171. pass
  172. {
  173. vertex_shader = VSDefault(vert_in);
  174. pixel_shader = PSDrawSrgbDecompress(vert_in);
  175. }
  176. }
  177. technique DrawSrgbDecompressMultiply
  178. {
  179. pass
  180. {
  181. vertex_shader = VSDefault(vert_in);
  182. pixel_shader = PSDrawSrgbDecompressMultiply(vert_in);
  183. }
  184. }
  185. technique DrawMultiply
  186. {
  187. pass
  188. {
  189. vertex_shader = VSDefault(vert_in);
  190. pixel_shader = PSDrawMultiply(vert_in);
  191. }
  192. }
  193. technique DrawTonemap
  194. {
  195. pass
  196. {
  197. vertex_shader = VSDefault(vert_in);
  198. pixel_shader = PSDrawTonemap(vert_in);
  199. }
  200. }
  201. technique DrawMultiplyTonemap
  202. {
  203. pass
  204. {
  205. vertex_shader = VSDefault(vert_in);
  206. pixel_shader = PSDrawMultiplyTonemap(vert_in);
  207. }
  208. }
  209. technique DrawPQ
  210. {
  211. pass
  212. {
  213. vertex_shader = VSDefault(vert_in);
  214. pixel_shader = PSDrawPQ(vert_in);
  215. }
  216. }
  217. technique DrawTonemapPQ
  218. {
  219. pass
  220. {
  221. vertex_shader = VSDefault(vert_in);
  222. pixel_shader = PSDrawTonemapPQ(vert_in);
  223. }
  224. }