1 #ifndef TEX2DANTIALIAS_H
2 #define TEX2DANTIALIAS_H
3
4 ///////////////////////////// GPL LICENSE NOTICE /////////////////////////////
5
6 // crt-royale: A full-featured CRT shader, with cheese.
7 // Copyright (C) 2014 TroggleMonkey <trogglemonkey@gmx.com>
8 //
9 // This program is free software; you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by the Free
11 // Software Foundation; either version 2 of the License, or any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 // more details.
17 //
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 // Place, Suite 330, Boston, MA 02111-1307 USA
21
22
23 ///////////////////////////////// DESCRIPTION ////////////////////////////////
24
25 // This file provides antialiased and subpixel-aware tex2D lookups.
26 // Requires: All functions share these requirements:
27 // 1.) All requirements of gamma-management.h must be satisfied!
28 // 2.) pixel_to_tex_uv must be a 2x2 matrix that transforms pixe-
29 // space offsets to texture uv offsets. You can get this with:
30 // const float2 duv_dx = ddx(tex_uv);
31 // const float2 duv_dy = ddy(tex_uv);
32 // const float2x2 pixel_to_tex_uv = float2x2(
33 // duv_dx.x, duv_dy.x,
34 // duv_dx.y, duv_dy.y);
35 // This is left to the user in case the current Cg profile
36 // doesn't support ddx()/ddy(). Ideally, the user could find
37 // calculate a distorted tangent-space mapping analytically.
38 // If not, a simple flat mapping can be obtained with:
39 // const float2 xy_to_uv_scale = IN.output_size *
40 // IN.video_size/IN.texture_size;
41 // const float2x2 pixel_to_tex_uv = float2x2(
42 // xy_to_uv_scale.x, 0.0,
43 // 0.0, xy_to_uv_scale.y);
44 // Optional: To set basic AA settings, #define ANTIALIAS_OVERRIDE_BASICS and:
45 // 1.) Set an antialiasing level:
46 // static const float aa_level = {0 (none),
47 // 1 (sample subpixels), 4, 5, 6, 7, 8, 12, 16, 20, 24}
48 // 2.) Set a filter type:
49 // static const float aa_filter = {
50 // 0 (Box, Separable), 1 (Box, Cylindrical),
51 // 2 (Tent, Separable), 3 (Tent, Cylindrical)
52 // 4 (Gaussian, Separable), 5 (Gaussian, Cylindrical)
53 // 6 (Cubic, Separable), 7 (Cubic, Cylindrical)
54 // 8 (Lanczos Sinc, Separable),
55 // 9 (Lanczos Jinc, Cylindrical)}
56 // If the input is unknown, a separable box filter is used.
57 // Note: Lanczos Jinc is terrible for sparse sampling, and
58 // using aa_axis_importance (see below) defeats the purpose.
59 // 3.) Mirror the sample pattern on odd frames?
60 // static const bool aa_temporal = {true, false]
61 // This helps rotational invariance but can look "fluttery."
62 // The user may #define ANTIALIAS_OVERRIDE_PARAMETERS to override
63 // (all of) the following default parameters with static or uniform
64 // constants (or an accessor function for subpixel offsets):
65 // 1.) Cubic parameters:
66 // static const float aa_cubic_c = 0.5;
67 // See http://www.imagemagick.org/Usage/filter/#mitchell
68 // 2.) Gaussian parameters:
69 // static const float aa_gauss_sigma =
70 // 0.5/aa_pixel_diameter;
71 // 3.) Set subpixel offsets. This requires an accessor function
72 // for compatibility with scalar runtime shader params. Return
73 // a float2 pixel offset in [-0.5, 0.5] for the red subpixel:
74 // float2 get_aa_subpixel_r_offset()
75 // The user may also #define ANTIALIAS_OVERRIDE_STATIC_CONSTANTS to
76 // override (all of) the following default static values. However,
77 // the file's structure requires them to be declared static const:
78 // 1.) static const float aa_lanczos_lobes = 3.0;
79 // 2.) static const float aa_gauss_support = 1.0/aa_pixel_diameter;
80 // Note the default tent/Gaussian support radii may appear
81 // arbitrary, but extensive testing found them nearly optimal
82 // for tough cases like strong distortion at low AA levels.
83 // (The Gaussian default is only best for practical gauss_sigma
84 // values; much larger gauss_sigmas ironically prefer slightly
85 // smaller support given sparse sampling, and vice versa.)
86 // 3.) static const float aa_tent_support = 1.0 / aa_pixel_diameter;
87 // 4.) static const float2 aa_xy_axis_importance:
88 // The sparse N-queens sampling grid interacts poorly with
89 // negative-lobed 2D filters. However, if aliasing is much
90 // stronger in one direction (e.g. horizontally with a phosphor
91 // mask), it can be useful to downplay sample offsets along the
92 // other axis. The support radius in each direction scales with
93 // aa_xy_axis_importance down to a minimum of 0.5 (box support),
94 // after which point only the offsets used for calculating
95 // weights continue to scale downward. This works as follows:
96 // If aa_xy_axis_importance = float2(1.0, 1.0/support_radius),
97 // the vertical support radius will drop to 1.0, and we'll just
98 // filter vertical offsets with the first filter lobe, while
99 // horizontal offsets go through the full multi-lobe filter.
100 // If aa_xy_axis_importance = float2(1.0, 0.0), the vertical
101 // support radius will drop to box support, and the vertical
102 // offsets will be ignored entirely (essentially giving us a
103 // box filter vertically). The former is potentially smoother
104 // (but less predictable) and the default behavior of Lanczos
105 // jinc, whereas the latter is sharper and the default behavior
106 // of cubics and Lanczos sinc.
107 // 5.) static const float aa_pixel_diameter: You can expand the
108 // pixel diameter to e.g. sqrt(2.0), which may be a better
109 // support range for cylindrical filters (they don't
110 // currently discard out-of-circle samples though).
111 // Finally, there are two miscellaneous options:
112 // 1.) If you want to antialias a manually tiled texture, you can
113 // #define ANTIALIAS_DISABLE_ANISOTROPIC to use tex2Dlod() to
114 // fix incompatibilities with anisotropic filtering. This is
115 // slower, and the Cg profile must support tex2Dlod().
116 // 2.) If aa_cubic_c is a runtime uniform, you can #define
117 // RUNTIME_ANTIALIAS_WEIGHTS to evaluate cubic weights once per
118 // fragment instead of at the usage site (which is used by
119 // default, because it enables static evaluation).
120 // Description:
121 // Each antialiased lookup follows these steps:
122 // 1.) Define a sample pattern of pixel offsets in the range of [-0.5, 0.5]
123 // pixels, spanning the diameter of a rectangular box filter.
124 // 2.) Scale these offsets by the support diameter of the user's chosen filter.
125 // 3.) Using these pixel offsets from the pixel center, compute the offsets to
126 // predefined subpixel locations.
127 // 4.) Compute filter weights based on subpixel offsets.
128 // Much of that can often be done at compile-time. At runtime:
129 // 1.) Project pixel-space offsets into uv-space with a matrix multiplication
130 // to get the uv offsets for each sample. Rectangular pixels have a
131 // diameter of 1.0. Circular pixels are not currently supported, but they
132 // might be better with a diameter of sqrt(2.0) to ensure there are no gaps
133 // between them.
134 // 2.) Load, weight, and sum samples.
135 // We use a sparse bilinear sampling grid, so there are two major implications:
136 // 1.) We can directly project the pixel-space support box into uv-space even
137 // if we're upsizing. This wouldn't be the case for nearest neighbor,
138 // where we'd have to expand the uv-space diameter to at least the support
139 // size to ensure sufficient filter support. In our case, this allows us
140 // to treat upsizing the same as downsizing and use static weighting. :)
141 // 2.) For decent results, negative-lobed filters must be computed based on
142 // separable weights, not radial distances, because the sparse sampling
143 // makes no guarantees about radial distributions. Even then, it's much
144 // better to set aa_xy_axis_importance to e.g. float2(1.0, 0.0) to use e.g.
145 // Lanczos2 horizontally and a box filter vertically. This is mainly due
146 // to the sparse N-queens sampling and a statistically enormous positive or
147 // negative covariance between horizontal and vertical weights.
148 //
149 // Design Decision Comments:
150 // "aa_temporal" mirrors the sample pattern on odd frames along the axis that
151 // keeps subpixel weights constant. This helps with rotational invariance, but
152 // it can cause distracting fluctuations, and horizontal and vertical edges
153 // will look the same. Using a different pattern on a shifted grid would
154 // exploit temporal AA better, but it would require a dynamic branch or a lot
155 // of conditional moves, so it's prohibitively slow for the minor benefit.
156
157
158 ///////////////////////////// SETTINGS MANAGEMENT ////////////////////////////
159
160 #ifndef ANTIALIAS_OVERRIDE_BASICS
161 // The following settings must be static constants:
162 static const float aa_level = 12.0;
163 static const float aa_filter = 0.0;
164 static const bool aa_temporal = false;
165 #endif
166
167 #ifndef ANTIALIAS_OVERRIDE_STATIC_CONSTANTS
168 // Users may override these parameters, but the file structure requires
169 // them to be static constants; see the descriptions above.
170 static const float aa_pixel_diameter = 1.0;
171 static const float aa_lanczos_lobes = 3.0;
172 static const float aa_gauss_support = 1.0 / aa_pixel_diameter;
173 static const float aa_tent_support = 1.0 / aa_pixel_diameter;
174
175 // If we're using a negative-lobed filter, default to using it horizontally
176 // only, and use only the first lobe vertically or a box filter, over a
177 // correspondingly smaller range. This compensates for the sparse sampling
178 // grid's typically large positive/negative x/y covariance.
179 static const float2 aa_xy_axis_importance =
180 aa_filter < 5.5 ? float2(1.0) : // Box, tent, Gaussian
181 aa_filter < 8.5 ? float2(1.0, 0.0) : // Cubic and Lanczos sinc
182 aa_filter < 9.5 ? float2(1.0, 1.0/aa_lanczos_lobes) : // Lanczos jinc
183 float2(1.0); // Default to box
184 #endif
185
186 #ifndef ANTIALIAS_OVERRIDE_PARAMETERS
187 // Users may override these values with their own uniform or static consts.
188 // Cubics: See http://www.imagemagick.org/Usage/filter/#mitchell
189 // 1.) "Keys cubics" with B = 1 - 2C are considered the highest quality.
190 // 2.) C = 0.5 (default) is Catmull-Rom; higher C's apply sharpening.
191 // 3.) C = 1.0/3.0 is the Mitchell-Netravali filter.
192 // 4.) C = 0.0 is a soft spline filter.
193 static const float aa_cubic_c = 0.5;
194 static const float aa_gauss_sigma = 0.5 / aa_pixel_diameter;
195 // Users may override the subpixel offset accessor function with their own.
196 // A function is used for compatibility with scalar runtime shader params.
get_aa_subpixel_r_offset()197 inline float2 get_aa_subpixel_r_offset()
198 {
199 return float2(0.0, 0.0);
200 }
201 #endif
202
203
204 ////////////////////////////////// INCLUDES //////////////////////////////////
205
206 #include "../../../../include/gamma-management.h"
207
208
209 ////////////////////////////////// CONSTANTS /////////////////////////////////
210
211 static const float aa_box_support = 0.5;
212 static const float aa_cubic_support = 2.0;
213
214
215 //////////////////////////// GLOBAL NON-CONSTANTS ////////////////////////////
216
217 // We'll want to define these only once per fragment at most.
218 #ifdef RUNTIME_ANTIALIAS_WEIGHTS
219 float aa_cubic_b;
220 float cubic_branch1_x3_coeff;
221 float cubic_branch1_x2_coeff;
222 float cubic_branch1_x0_coeff;
223 float cubic_branch2_x3_coeff;
224 float cubic_branch2_x2_coeff;
225 float cubic_branch2_x1_coeff;
226 float cubic_branch2_x0_coeff;
227 #endif
228
229
230 /////////////////////////////////// HELPERS //////////////////////////////////
231
assign_aa_cubic_constants()232 void assign_aa_cubic_constants()
233 {
234 // Compute cubic coefficients on demand at runtime, and save them to global
235 // uniforms. The B parameter is computed from C, because "Keys cubics"
236 // with B = 1 - 2C are considered the highest quality.
237 #ifdef RUNTIME_ANTIALIAS_WEIGHTS
238 if(aa_filter > 5.5 && aa_filter < 7.5)
239 {
240 aa_cubic_b = 1.0 - 2.0*aa_cubic_c;
241 cubic_branch1_x3_coeff = 12.0 - 9.0*aa_cubic_b - 6.0*aa_cubic_c;
242 cubic_branch1_x2_coeff = -18.0 + 12.0*aa_cubic_b + 6.0*aa_cubic_c;
243 cubic_branch1_x0_coeff = 6.0 - 2.0 * aa_cubic_b;
244 cubic_branch2_x3_coeff = -aa_cubic_b - 6.0 * aa_cubic_c;
245 cubic_branch2_x2_coeff = 6.0*aa_cubic_b + 30.0*aa_cubic_c;
246 cubic_branch2_x1_coeff = -12.0*aa_cubic_b - 48.0*aa_cubic_c;
247 cubic_branch2_x0_coeff = 8.0*aa_cubic_b + 24.0*aa_cubic_c;
248 }
249 #endif
250 }
251
get_subpixel_support_diam_and_final_axis_importance()252 inline float4 get_subpixel_support_diam_and_final_axis_importance()
253 {
254 // Statically select the base support radius:
255 static const float base_support_radius =
256 aa_filter < 1.5 ? aa_box_support :
257 aa_filter < 3.5 ? aa_tent_support :
258 aa_filter < 5.5 ? aa_gauss_support :
259 aa_filter < 7.5 ? aa_cubic_support :
260 aa_filter < 9.5 ? aa_lanczos_lobes :
261 aa_box_support; // Default to box
262 // Expand the filter support for subpixel filtering.
263 const float2 subpixel_support_radius_raw =
264 float2(base_support_radius) + abs(get_aa_subpixel_r_offset());
265 if(aa_filter < 1.5)
266 {
267 // Ignore aa_xy_axis_importance for box filtering.
268 const float2 subpixel_support_diam =
269 2.0 * subpixel_support_radius_raw;
270 const float2 final_axis_importance = float2(1.0);
271 return float4(subpixel_support_diam, final_axis_importance);
272 }
273 else
274 {
275 // Scale the support window by aa_xy_axis_importance, but don't narrow
276 // it further than box support. This allows decent vertical AA without
277 // messing up horizontal weights or using something silly like Lanczos4
278 // horizontally with a huge vertical average over an 8-pixel radius.
279 const float2 subpixel_support_radius = max(float2(aa_box_support, aa_box_support),
280 subpixel_support_radius_raw * aa_xy_axis_importance);
281 // Adjust aa_xy_axis_importance to compensate for what's already done:
282 const float2 final_axis_importance = aa_xy_axis_importance *
283 subpixel_support_radius_raw/subpixel_support_radius;
284 const float2 subpixel_support_diam = 2.0 * subpixel_support_radius;
285 return float4(subpixel_support_diam, final_axis_importance);
286 }
287 }
288
289
290 /////////////////////////// FILTER WEIGHT FUNCTIONS //////////////////////////
291
eval_box_filter(const float dist)292 inline float eval_box_filter(const float dist)
293 {
294 return float(abs(dist) <= aa_box_support);
295 }
296
eval_separable_box_filter(const float2 offset)297 inline float eval_separable_box_filter(const float2 offset)
298 {
299 return float(all(bool2((abs(offset.x) <= aa_box_support), (abs(offset.y) <= aa_box_support))));
300 }
301
eval_tent_filter(const float dist)302 inline float eval_tent_filter(const float dist)
303 {
304 return clamp((aa_tent_support - dist)/
305 aa_tent_support, 0.0, 1.0);
306 }
307
eval_gaussian_filter(const float dist)308 inline float eval_gaussian_filter(const float dist)
309 {
310 return exp(-(dist*dist) / (2.0*aa_gauss_sigma*aa_gauss_sigma));
311 }
312
eval_cubic_filter(const float dist)313 inline float eval_cubic_filter(const float dist)
314 {
315 // Compute coefficients like assign_aa_cubic_constants(), but statically.
316 #ifndef RUNTIME_ANTIALIAS_WEIGHTS
317 // When runtime weights are used, these values are instead written to
318 // global uniforms at the beginning of each tex2Daa* call.
319 const float aa_cubic_b = 1.0 - 2.0*aa_cubic_c;
320 const float cubic_branch1_x3_coeff = 12.0 - 9.0*aa_cubic_b - 6.0*aa_cubic_c;
321 const float cubic_branch1_x2_coeff = -18.0 + 12.0*aa_cubic_b + 6.0*aa_cubic_c;
322 const float cubic_branch1_x0_coeff = 6.0 - 2.0 * aa_cubic_b;
323 const float cubic_branch2_x3_coeff = -aa_cubic_b - 6.0 * aa_cubic_c;
324 const float cubic_branch2_x2_coeff = 6.0*aa_cubic_b + 30.0*aa_cubic_c;
325 const float cubic_branch2_x1_coeff = -12.0*aa_cubic_b - 48.0*aa_cubic_c;
326 const float cubic_branch2_x0_coeff = 8.0*aa_cubic_b + 24.0*aa_cubic_c;
327 #endif
328 const float abs_dist = abs(dist);
329 // Compute the cubic based on the Horner's method formula in:
330 // http://www.cs.utexas.edu/users/fussell/courses/cs384g/lectures/mitchell/Mitchell.pdf
331 return (abs_dist < 1.0 ?
332 (cubic_branch1_x3_coeff*abs_dist +
333 cubic_branch1_x2_coeff)*abs_dist*abs_dist +
334 cubic_branch1_x0_coeff :
335 abs_dist < 2.0 ?
336 ((cubic_branch2_x3_coeff*abs_dist +
337 cubic_branch2_x2_coeff)*abs_dist +
338 cubic_branch2_x1_coeff)*abs_dist + cubic_branch2_x0_coeff :
339 0.0)/6.0;
340 }
341
eval_separable_cubic_filter(const float2 offset)342 inline float eval_separable_cubic_filter(const float2 offset)
343 {
344 // This is faster than using a specific float2 version:
345 return eval_cubic_filter(offset.x) *
346 eval_cubic_filter(offset.y);
347 }
348
eval_sinc_filter(const float2 offset)349 inline float2 eval_sinc_filter(const float2 offset)
350 {
351 // It's faster to let the caller handle the zero case, or at least it
352 // was when I used macros and the shader preset took a full minute to load.
353 const float2 pi_offset = pi * offset;
354 return sin(pi_offset)/pi_offset;
355 }
356
eval_separable_lanczos_sinc_filter(const float2 offset_unsafe)357 inline float eval_separable_lanczos_sinc_filter(const float2 offset_unsafe)
358 {
359 // Note: For sparse sampling, you really need to pick an axis to use
360 // Lanczos along (e.g. set aa_xy_axis_importance = float2(1.0, 0.0)).
361 const float2 offset = FIX_ZERO(offset_unsafe);
362 const float2 xy_weights = eval_sinc_filter(offset) *
363 eval_sinc_filter(offset/aa_lanczos_lobes);
364 return xy_weights.x * xy_weights.y;
365 }
366
eval_jinc_filter_unorm(const float x)367 inline float eval_jinc_filter_unorm(const float x)
368 {
369 // This is a Jinc approximation for x in [0, 45). We'll use x in range
370 // [0, 4*pi) or so. There are faster/closer approximations based on
371 // piecewise cubics from [0, 45) and asymptotic approximations beyond that,
372 // but this has a maximum absolute error < 1/512, and it's simpler/faster
373 // for shaders...not that it's all that useful for sparse sampling anyway.
374 const float point3845_x = 0.38448566093564*x;
375 const float exp_term = exp(-(point3845_x*point3845_x));
376 const float point8154_plus_x = 0.815362332840791 + x;
377 const float cos_term = cos(point8154_plus_x);
378 return (
379 0.0264727330997042*min(x, 6.83134964622778) +
380 0.680823557250528*exp_term +
381 -0.0597255978950933*min(7.41043194481873, x)*cos_term /
382 (point8154_plus_x + 0.0646074538634482*(x*x) +
383 cos(x)*max(exp_term, cos(x) + cos_term)) -
384 0.180837503591406);
385 }
386
eval_jinc_filter(const float dist)387 inline float eval_jinc_filter(const float dist)
388 {
389 return eval_jinc_filter_unorm(pi * dist);
390 }
391
eval_lanczos_jinc_filter(const float dist)392 inline float eval_lanczos_jinc_filter(const float dist)
393 {
394 return eval_jinc_filter(dist) * eval_jinc_filter(dist/aa_lanczos_lobes);
395 }
396
397
eval_unorm_rgb_weights(const float2 offset,const float2 final_axis_importance)398 inline float3 eval_unorm_rgb_weights(const float2 offset,
399 const float2 final_axis_importance)
400 {
401 // Requires: 1.) final_axis_impportance must be computed according to
402 // get_subpixel_support_diam_and_final_axis_importance().
403 // 2.) aa_filter must be a global constant.
404 // 3.) offset must be an xy pixel offset in the range:
405 // ([-subpixel_support_diameter.x/2,
406 // subpixel_support_diameter.x/2],
407 // [-subpixel_support_diameter.y/2,
408 // subpixel_support_diameter.y/2])
409 // Returns: Sample weights at R/G/B destination subpixels for the
410 // given xy pixel offset.
411 const float2 offset_g = offset * final_axis_importance;
412 const float2 aa_r_offset = get_aa_subpixel_r_offset();
413 const float2 offset_r = offset_g - aa_r_offset * final_axis_importance;
414 const float2 offset_b = offset_g + aa_r_offset * final_axis_importance;
415 // Statically select a filter:
416 if(aa_filter < 0.5)
417 {
418 return float3(eval_separable_box_filter(offset_r),
419 eval_separable_box_filter(offset_g),
420 eval_separable_box_filter(offset_b));
421 }
422 else if(aa_filter < 1.5)
423 {
424 return float3(eval_box_filter(length(offset_r)),
425 eval_box_filter(length(offset_g)),
426 eval_box_filter(length(offset_b)));
427 }
428 else if(aa_filter < 2.5)
429 {
430 return float3(
431 eval_tent_filter(offset_r.x) * eval_tent_filter(offset_r.y),
432 eval_tent_filter(offset_g.x) * eval_tent_filter(offset_g.y),
433 eval_tent_filter(offset_b.x) * eval_tent_filter(offset_b.y));
434 }
435 else if(aa_filter < 3.5)
436 {
437 return float3(eval_tent_filter(length(offset_r)),
438 eval_tent_filter(length(offset_g)),
439 eval_tent_filter(length(offset_b)));
440 }
441 else if(aa_filter < 4.5)
442 {
443 return float3(
444 eval_gaussian_filter(offset_r.x) * eval_gaussian_filter(offset_r.y),
445 eval_gaussian_filter(offset_g.x) * eval_gaussian_filter(offset_g.y),
446 eval_gaussian_filter(offset_b.x) * eval_gaussian_filter(offset_b.y));
447 }
448 else if(aa_filter < 5.5)
449 {
450 return float3(eval_gaussian_filter(length(offset_r)),
451 eval_gaussian_filter(length(offset_g)),
452 eval_gaussian_filter(length(offset_b)));
453 }
454 else if(aa_filter < 6.5)
455 {
456 return float3(
457 eval_cubic_filter(offset_r.x) * eval_cubic_filter(offset_r.y),
458 eval_cubic_filter(offset_g.x) * eval_cubic_filter(offset_g.y),
459 eval_cubic_filter(offset_b.x) * eval_cubic_filter(offset_b.y));
460 }
461 else if(aa_filter < 7.5)
462 {
463 return float3(eval_cubic_filter(length(offset_r)),
464 eval_cubic_filter(length(offset_g)),
465 eval_cubic_filter(length(offset_b)));
466 }
467 else if(aa_filter < 8.5)
468 {
469 return float3(eval_separable_lanczos_sinc_filter(offset_r),
470 eval_separable_lanczos_sinc_filter(offset_g),
471 eval_separable_lanczos_sinc_filter(offset_b));
472 }
473 else if(aa_filter < 9.5)
474 {
475 return float3(eval_lanczos_jinc_filter(length(offset_r)),
476 eval_lanczos_jinc_filter(length(offset_g)),
477 eval_lanczos_jinc_filter(length(offset_b)));
478 }
479 else
480 {
481 // Default to a box, because Lanczos Jinc is so bad. ;)
482 return float3(eval_separable_box_filter(offset_r),
483 eval_separable_box_filter(offset_g),
484 eval_separable_box_filter(offset_b));
485 }
486 }
487
488
489 ////////////////////////////// HELPER FUNCTIONS //////////////////////////////
490
tex2Daa_tiled_linearize(const sampler2D samp,const float2 s)491 inline float4 tex2Daa_tiled_linearize(const sampler2D samp, const float2 s)
492 {
493 // If we're manually tiling a texture, anisotropic filtering can get
494 // confused. This is one workaround:
495 #ifdef ANTIALIAS_DISABLE_ANISOTROPIC
496 // TODO: Use tex2Dlod_linearize with a calculated mip level.
497 return tex2Dlod_linearize(samp, float4(s, 0.0, 0.0));
498 #else
499 return tex2D_linearize(samp, s);
500 #endif
501 }
502
get_frame_sign(const float frame)503 inline float2 get_frame_sign(const float frame)
504 {
505 if(aa_temporal)
506 {
507 // Mirror the sampling pattern for odd frames in a direction that
508 // lets us keep the same subpixel sample weights:
509 const float frame_odd = float(fmod(frame, 2.0) > 0.5);
510 const float2 aa_r_offset = get_aa_subpixel_r_offset();
511 const float2 mirror = -float2(abs(aa_r_offset.x) < (FIX_ZERO(0.0)), abs(aa_r_offset.y) < (FIX_ZERO(0.0)));
512 return mirror;
513 }
514 else
515 {
516 return float2(1.0, 1.0);
517 }
518 }
519
520
521 ///////////////////////// ANTIALIASED TEXTURE LOOKUPS ////////////////////////
522
tex2Daa_subpixel_weights_only(const sampler2D tex,const float2 tex_uv,const float2x2 pixel_to_tex_uv)523 float3 tex2Daa_subpixel_weights_only(const sampler2D tex,
524 const float2 tex_uv, const float2x2 pixel_to_tex_uv)
525 {
526 // This function is unlike the others: Just perform a single independent
527 // lookup for each subpixel. It may be very aliased.
528 const float2 aa_r_offset = get_aa_subpixel_r_offset();
529 const float2 aa_r_offset_uv_offset = mul(pixel_to_tex_uv, aa_r_offset);
530 const float color_g = tex2D_linearize(tex, tex_uv).g;
531 const float color_r = tex2D_linearize(tex, tex_uv + aa_r_offset_uv_offset).r;
532 const float color_b = tex2D_linearize(tex, tex_uv - aa_r_offset_uv_offset).b;
533 return float3(color_r, color_g, color_b);
534 }
535
536 // The tex2Daa* functions compile very slowly due to all the macros and
537 // compile-time math, so only include the ones we'll actually use!
tex2Daa4x(const sampler2D tex,const float2 tex_uv,const float2x2 pixel_to_tex_uv,const float frame)538 float3 tex2Daa4x(const sampler2D tex, const float2 tex_uv,
539 const float2x2 pixel_to_tex_uv, const float frame)
540 {
541 // Use an RGMS4 pattern (4-queens):
542 // . . Q . : off =(-1.5, -1.5)/4 + (2.0, 0.0)/4
543 // Q . . . : off =(-1.5, -1.5)/4 + (0.0, 1.0)/4
544 // . . . Q : off =(-1.5, -1.5)/4 + (3.0, 2.0)/4
545 // . Q . . : off =(-1.5, -1.5)/4 + (1.0, 3.0)/4
546 // Static screenspace sample offsets (compute some implicitly):
547 static const float grid_size = 4.0;
548 assign_aa_cubic_constants();
549 const float4 ssd_fai = get_subpixel_support_diam_and_final_axis_importance();
550 const float2 subpixel_support_diameter = ssd_fai.xy;
551 const float2 final_axis_importance = ssd_fai.zw;
552 const float2 xy_step = float2(1.0,1.0)/grid_size * subpixel_support_diameter;
553 const float2 xy_start_offset = float2(0.5 - grid_size*0.5,0.5 - grid_size*0.5) * xy_step;
554 // Get the xy offset of each sample. Exploit diagonal symmetry:
555 const float2 xy_offset0 = xy_start_offset + float2(2.0, 0.0) * xy_step;
556 const float2 xy_offset1 = xy_start_offset + float2(0.0, 1.0) * xy_step;
557 // Compute subpixel weights, and exploit diagonal symmetry for speed.
558 const float3 w0 = eval_unorm_rgb_weights(xy_offset0, final_axis_importance);
559 const float3 w1 = eval_unorm_rgb_weights(xy_offset1, final_axis_importance);
560 const float3 w2 = w1.bgr;
561 const float3 w3 = w0.bgr;
562 // Get the weight sum to normalize the total to 1.0 later:
563 const float3 half_sum = w0 + w1;
564 const float3 w_sum = half_sum + half_sum.bgr;
565 const float3 w_sum_inv = float3(1.0,1.0,1.0)/(w_sum);
566 // Scale the pixel-space to texture offset matrix by the pixel diameter.
567 const float2x2 true_pixel_to_tex_uv =
568 float2x2((pixel_to_tex_uv * aa_pixel_diameter));
569 // Get uv sample offsets, mirror on odd frames if directed, and exploit
570 // diagonal symmetry:
571 const float2 frame_sign = get_frame_sign(frame);
572 const float2 uv_offset0 = mul(true_pixel_to_tex_uv, xy_offset0 * frame_sign);
573 const float2 uv_offset1 = mul(true_pixel_to_tex_uv, xy_offset1 * frame_sign);
574 // Load samples, linearizing if necessary, etc.:
575 const float3 sample0 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset0).rgb;
576 const float3 sample1 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset1).rgb;
577 const float3 sample2 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset1).rgb;
578 const float3 sample3 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset0).rgb;
579 // Sum weighted samples (weight sum must equal 1.0 for each channel):
580 return w_sum_inv * (w0 * sample0 + w1 * sample1 +
581 w2 * sample2 + w3 * sample3);
582 }
583
tex2Daa5x(const sampler2D tex,const float2 tex_uv,const float2x2 pixel_to_tex_uv,const float frame)584 float3 tex2Daa5x(const sampler2D tex, const float2 tex_uv,
585 const float2x2 pixel_to_tex_uv, const float frame)
586 {
587 // Use a diagonally symmetric 5-queens pattern:
588 // . Q . . . : off =(-2.0, -2.0)/5 + (1.0, 0.0)/5
589 // . . . . Q : off =(-2.0, -2.0)/5 + (4.0, 1.0)/5
590 // . . Q . . : off =(-2.0, -2.0)/5 + (2.0, 2.0)/5
591 // Q . . . . : off =(-2.0, -2.0)/5 + (0.0, 3.0)/5
592 // . . . Q . : off =(-2.0, -2.0)/5 + (3.0, 4.0)/5
593 // Static screenspace sample offsets (compute some implicitly):
594 static const float grid_size = 5.0;
595 assign_aa_cubic_constants();
596 const float4 ssd_fai = get_subpixel_support_diam_and_final_axis_importance();
597 const float2 subpixel_support_diameter = ssd_fai.xy;
598 const float2 final_axis_importance = ssd_fai.zw;
599 const float2 xy_step = float2(1.0)/grid_size * subpixel_support_diameter;
600 const float2 xy_start_offset = float2(0.5 - grid_size*0.5) * xy_step;
601 // Get the xy offset of each sample. Exploit diagonal symmetry:
602 const float2 xy_offset0 = xy_start_offset + float2(1.0, 0.0) * xy_step;
603 const float2 xy_offset1 = xy_start_offset + float2(4.0, 1.0) * xy_step;
604 const float2 xy_offset2 = xy_start_offset + float2(2.0, 2.0) * xy_step;
605 // Compute subpixel weights, and exploit diagonal symmetry for speed.
606 const float3 w0 = eval_unorm_rgb_weights(xy_offset0, final_axis_importance);
607 const float3 w1 = eval_unorm_rgb_weights(xy_offset1, final_axis_importance);
608 const float3 w2 = eval_unorm_rgb_weights(xy_offset2, final_axis_importance);
609 const float3 w3 = w1.bgr;
610 const float3 w4 = w0.bgr;
611 // Get the weight sum to normalize the total to 1.0 later:
612 const float3 w_sum_inv = float3(1.0)/(w0 + w1 + w2 + w3 + w4);
613 // Scale the pixel-space to texture offset matrix by the pixel diameter.
614 const float2x2 true_pixel_to_tex_uv =
615 float2x2((pixel_to_tex_uv * aa_pixel_diameter));
616 // Get uv sample offsets, mirror on odd frames if directed, and exploit
617 // diagonal symmetry:
618 const float2 frame_sign = get_frame_sign(frame);
619 const float2 uv_offset0 = mul(true_pixel_to_tex_uv, xy_offset0 * frame_sign);
620 const float2 uv_offset1 = mul(true_pixel_to_tex_uv, xy_offset1 * frame_sign);
621 // Load samples, linearizing if necessary, etc.:
622 const float3 sample0 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset0).rgb;
623 const float3 sample1 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset1).rgb;
624 const float3 sample2 = tex2Daa_tiled_linearize(tex, tex_uv).rgb;
625 const float3 sample3 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset1).rgb;
626 const float3 sample4 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset0).rgb;
627 // Sum weighted samples (weight sum must equal 1.0 for each channel):
628 return w_sum_inv * (w0 * sample0 + w1 * sample1 +
629 w2 * sample2 + w3 * sample3 + w4 * sample4);
630 }
631
tex2Daa6x(const sampler2D tex,const float2 tex_uv,const float2x2 pixel_to_tex_uv,const float frame)632 float3 tex2Daa6x(const sampler2D tex, const float2 tex_uv,
633 const float2x2 pixel_to_tex_uv, const float frame)
634 {
635 // Use a diagonally symmetric 6-queens pattern with a stronger horizontal
636 // than vertical slant:
637 // . . . . Q . : off =(-2.5, -2.5)/6 + (4.0, 0.0)/6
638 // . . Q . . . : off =(-2.5, -2.5)/6 + (2.0, 1.0)/6
639 // Q . . . . . : off =(-2.5, -2.5)/6 + (0.0, 2.0)/6
640 // . . . . . Q : off =(-2.5, -2.5)/6 + (5.0, 3.0)/6
641 // . . . Q . . : off =(-2.5, -2.5)/6 + (3.0, 4.0)/6
642 // . Q . . . . : off =(-2.5, -2.5)/6 + (1.0, 5.0)/6
643 // Static screenspace sample offsets (compute some implicitly):
644 static const float grid_size = 6.0;
645 assign_aa_cubic_constants();
646 const float4 ssd_fai = get_subpixel_support_diam_and_final_axis_importance();
647 const float2 subpixel_support_diameter = ssd_fai.xy;
648 const float2 final_axis_importance = ssd_fai.zw;
649 const float2 xy_step = float2(1.0)/grid_size * subpixel_support_diameter;
650 const float2 xy_start_offset = float2(0.5 - grid_size*0.5) * xy_step;
651 // Get the xy offset of each sample. Exploit diagonal symmetry:
652 const float2 xy_offset0 = xy_start_offset + float2(4.0, 0.0) * xy_step;
653 const float2 xy_offset1 = xy_start_offset + float2(2.0, 1.0) * xy_step;
654 const float2 xy_offset2 = xy_start_offset + float2(0.0, 2.0) * xy_step;
655 // Compute subpixel weights, and exploit diagonal symmetry for speed.
656 const float3 w0 = eval_unorm_rgb_weights(xy_offset0, final_axis_importance);
657 const float3 w1 = eval_unorm_rgb_weights(xy_offset1, final_axis_importance);
658 const float3 w2 = eval_unorm_rgb_weights(xy_offset2, final_axis_importance);
659 const float3 w3 = w2.bgr;
660 const float3 w4 = w1.bgr;
661 const float3 w5 = w0.bgr;
662 // Get the weight sum to normalize the total to 1.0 later:
663 const float3 half_sum = w0 + w1 + w2;
664 const float3 w_sum = half_sum + half_sum.bgr;
665 const float3 w_sum_inv = float3(1.0)/(w_sum);
666 // Scale the pixel-space to texture offset matrix by the pixel diameter.
667 const float2x2 true_pixel_to_tex_uv =
668 float2x2((pixel_to_tex_uv * aa_pixel_diameter));
669 // Get uv sample offsets, mirror on odd frames if directed, and exploit
670 // diagonal symmetry:
671 const float2 frame_sign = get_frame_sign(frame);
672 const float2 uv_offset0 = mul(true_pixel_to_tex_uv, xy_offset0 * frame_sign);
673 const float2 uv_offset1 = mul(true_pixel_to_tex_uv, xy_offset1 * frame_sign);
674 const float2 uv_offset2 = mul(true_pixel_to_tex_uv, xy_offset2 * frame_sign);
675 // Load samples, linearizing if necessary, etc.:
676 const float3 sample0 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset0).rgb;
677 const float3 sample1 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset1).rgb;
678 const float3 sample2 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset2).rgb;
679 const float3 sample3 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset2).rgb;
680 const float3 sample4 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset1).rgb;
681 const float3 sample5 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset0).rgb;
682 // Sum weighted samples (weight sum must equal 1.0 for each channel):
683 return w_sum_inv * (w0 * sample0 + w1 * sample1 + w2 * sample2 +
684 w3 * sample3 + w4 * sample4 + w5 * sample5);
685 }
686
tex2Daa7x(const sampler2D tex,const float2 tex_uv,const float2x2 pixel_to_tex_uv,const float frame)687 float3 tex2Daa7x(const sampler2D tex, const float2 tex_uv,
688 const float2x2 pixel_to_tex_uv, const float frame)
689 {
690 // Use a diagonally symmetric 7-queens pattern with a queen in the center:
691 // . Q . . . . . : off =(-3.0, -3.0)/7 + (1.0, 0.0)/7
692 // . . . . Q . . : off =(-3.0, -3.0)/7 + (4.0, 1.0)/7
693 // Q . . . . . . : off =(-3.0, -3.0)/7 + (0.0, 2.0)/7
694 // . . . Q . . . : off =(-3.0, -3.0)/7 + (3.0, 3.0)/7
695 // . . . . . . Q : off =(-3.0, -3.0)/7 + (6.0, 4.0)/7
696 // . . Q . . . . : off =(-3.0, -3.0)/7 + (2.0, 5.0)/7
697 // . . . . . Q . : off =(-3.0, -3.0)/7 + (5.0, 6.0)/7
698 static const float grid_size = 7.0;
699 assign_aa_cubic_constants();
700 const float4 ssd_fai = get_subpixel_support_diam_and_final_axis_importance();
701 const float2 subpixel_support_diameter = ssd_fai.xy;
702 const float2 final_axis_importance = ssd_fai.zw;
703 const float2 xy_step = float2(1.0)/grid_size * subpixel_support_diameter;
704 const float2 xy_start_offset = float2(0.5 - grid_size*0.5) * xy_step;
705 // Get the xy offset of each sample. Exploit diagonal symmetry:
706 const float2 xy_offset0 = xy_start_offset + float2(1.0, 0.0) * xy_step;
707 const float2 xy_offset1 = xy_start_offset + float2(4.0, 1.0) * xy_step;
708 const float2 xy_offset2 = xy_start_offset + float2(0.0, 2.0) * xy_step;
709 const float2 xy_offset3 = xy_start_offset + float2(3.0, 3.0) * xy_step;
710 // Compute subpixel weights, and exploit diagonal symmetry for speed.
711 const float3 w0 = eval_unorm_rgb_weights(xy_offset0, final_axis_importance);
712 const float3 w1 = eval_unorm_rgb_weights(xy_offset1, final_axis_importance);
713 const float3 w2 = eval_unorm_rgb_weights(xy_offset2, final_axis_importance);
714 const float3 w3 = eval_unorm_rgb_weights(xy_offset3, final_axis_importance);
715 const float3 w4 = w2.bgr;
716 const float3 w5 = w1.bgr;
717 const float3 w6 = w0.bgr;
718 // Get the weight sum to normalize the total to 1.0 later:
719 const float3 half_sum = w0 + w1 + w2;
720 const float3 w_sum = half_sum + half_sum.bgr + w3;
721 const float3 w_sum_inv = float3(1.0)/(w_sum);
722 // Scale the pixel-space to texture offset matrix by the pixel diameter.
723 const float2x2 true_pixel_to_tex_uv =
724 float2x2((pixel_to_tex_uv * aa_pixel_diameter));
725 // Get uv sample offsets, mirror on odd frames if directed, and exploit
726 // diagonal symmetry:
727 const float2 frame_sign = get_frame_sign(frame);
728 const float2 uv_offset0 = mul(true_pixel_to_tex_uv, xy_offset0 * frame_sign);
729 const float2 uv_offset1 = mul(true_pixel_to_tex_uv, xy_offset1 * frame_sign);
730 const float2 uv_offset2 = mul(true_pixel_to_tex_uv, xy_offset2 * frame_sign);
731 // Load samples, linearizing if necessary, etc.:
732 const float3 sample0 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset0).rgb;
733 const float3 sample1 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset1).rgb;
734 const float3 sample2 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset2).rgb;
735 const float3 sample3 = tex2Daa_tiled_linearize(tex, tex_uv).rgb;
736 const float3 sample4 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset2).rgb;
737 const float3 sample5 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset1).rgb;
738 const float3 sample6 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset0).rgb;
739 // Sum weighted samples (weight sum must equal 1.0 for each channel):
740 return w_sum_inv * (
741 w0 * sample0 + w1 * sample1 + w2 * sample2 + w3 * sample3 +
742 w4 * sample4 + w5 * sample5 + w6 * sample6);
743 }
744
tex2Daa8x(const sampler2D tex,const float2 tex_uv,const float2x2 pixel_to_tex_uv,const float frame)745 float3 tex2Daa8x(const sampler2D tex, const float2 tex_uv,
746 const float2x2 pixel_to_tex_uv, const float frame)
747 {
748 // Use a diagonally symmetric 8-queens pattern.
749 // . . Q . . . . . : off =(-3.5, -3.5)/8 + (2.0, 0.0)/8
750 // . . . . Q . . . : off =(-3.5, -3.5)/8 + (4.0, 1.0)/8
751 // . Q . . . . . . : off =(-3.5, -3.5)/8 + (1.0, 2.0)/8
752 // . . . . . . . Q : off =(-3.5, -3.5)/8 + (7.0, 3.0)/8
753 // Q . . . . . . . : off =(-3.5, -3.5)/8 + (0.0, 4.0)/8
754 // . . . . . . Q . : off =(-3.5, -3.5)/8 + (6.0, 5.0)/8
755 // . . . Q . . . . : off =(-3.5, -3.5)/8 + (3.0, 6.0)/8
756 // . . . . . Q . . : off =(-3.5, -3.5)/8 + (5.0, 7.0)/8
757 static const float grid_size = 8.0;
758 assign_aa_cubic_constants();
759 const float4 ssd_fai = get_subpixel_support_diam_and_final_axis_importance();
760 const float2 subpixel_support_diameter = ssd_fai.xy;
761 const float2 final_axis_importance = ssd_fai.zw;
762 const float2 xy_step = float2(1.0)/grid_size * subpixel_support_diameter;
763 const float2 xy_start_offset = float2(0.5 - grid_size*0.5) * xy_step;
764 // Get the xy offset of each sample. Exploit diagonal symmetry:
765 const float2 xy_offset0 = xy_start_offset + float2(2.0, 0.0) * xy_step;
766 const float2 xy_offset1 = xy_start_offset + float2(4.0, 1.0) * xy_step;
767 const float2 xy_offset2 = xy_start_offset + float2(1.0, 2.0) * xy_step;
768 const float2 xy_offset3 = xy_start_offset + float2(7.0, 3.0) * xy_step;
769 // Compute subpixel weights, and exploit diagonal symmetry for speed.
770 const float3 w0 = eval_unorm_rgb_weights(xy_offset0, final_axis_importance);
771 const float3 w1 = eval_unorm_rgb_weights(xy_offset1, final_axis_importance);
772 const float3 w2 = eval_unorm_rgb_weights(xy_offset2, final_axis_importance);
773 const float3 w3 = eval_unorm_rgb_weights(xy_offset3, final_axis_importance);
774 const float3 w4 = w3.bgr;
775 const float3 w5 = w2.bgr;
776 const float3 w6 = w1.bgr;
777 const float3 w7 = w0.bgr;
778 // Get the weight sum to normalize the total to 1.0 later:
779 const float3 half_sum = w0 + w1 + w2 + w3;
780 const float3 w_sum = half_sum + half_sum.bgr;
781 const float3 w_sum_inv = float3(1.0)/(w_sum);
782 // Scale the pixel-space to texture offset matrix by the pixel diameter.
783 const float2x2 true_pixel_to_tex_uv =
784 float2x2((pixel_to_tex_uv * aa_pixel_diameter));
785 // Get uv sample offsets, and mirror on odd frames if directed:
786 const float2 frame_sign = get_frame_sign(frame);
787 const float2 uv_offset0 = mul(true_pixel_to_tex_uv, xy_offset0 * frame_sign);
788 const float2 uv_offset1 = mul(true_pixel_to_tex_uv, xy_offset1 * frame_sign);
789 const float2 uv_offset2 = mul(true_pixel_to_tex_uv, xy_offset2 * frame_sign);
790 const float2 uv_offset3 = mul(true_pixel_to_tex_uv, xy_offset3 * frame_sign);
791 // Load samples, linearizing if necessary, etc.:
792 const float3 sample0 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset0).rgb;
793 const float3 sample1 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset1).rgb;
794 const float3 sample2 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset2).rgb;
795 const float3 sample3 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset3).rgb;
796 const float3 sample4 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset3).rgb;
797 const float3 sample5 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset2).rgb;
798 const float3 sample6 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset1).rgb;
799 const float3 sample7 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset0).rgb;
800 // Sum weighted samples (weight sum must equal 1.0 for each channel):
801 return w_sum_inv * (
802 w0 * sample0 + w1 * sample1 + w2 * sample2 + w3 * sample3 +
803 w4 * sample4 + w5 * sample5 + w6 * sample6 + w7 * sample7);
804 }
805
tex2Daa12x(const sampler2D tex,const float2 tex_uv,const float2x2 pixel_to_tex_uv,const float frame)806 float3 tex2Daa12x(const sampler2D tex, const float2 tex_uv,
807 const float2x2 pixel_to_tex_uv, const float frame)
808 {
809 // Use a diagonally symmetric 12-superqueens pattern where no 3 points are
810 // exactly collinear.
811 // . . . Q . . . . . . . . : off =(-5.5, -5.5)/12 + (3.0, 0.0)/12
812 // . . . . . . . . . Q . . : off =(-5.5, -5.5)/12 + (9.0, 1.0)/12
813 // . . . . . . Q . . . . . : off =(-5.5, -5.5)/12 + (6.0, 2.0)/12
814 // . Q . . . . . . . . . . : off =(-5.5, -5.5)/12 + (1.0, 3.0)/12
815 // . . . . . . . . . . . Q : off =(-5.5, -5.5)/12 + (11.0, 4.0)/12
816 // . . . . Q . . . . . . . : off =(-5.5, -5.5)/12 + (4.0, 5.0)/12
817 // . . . . . . . Q . . . . : off =(-5.5, -5.5)/12 + (7.0, 6.0)/12
818 // Q . . . . . . . . . . . : off =(-5.5, -5.5)/12 + (0.0, 7.0)/12
819 // . . . . . . . . . . Q . : off =(-5.5, -5.5)/12 + (10.0, 8.0)/12
820 // . . . . . Q . . . . . . : off =(-5.5, -5.5)/12 + (5.0, 9.0)/12
821 // . . Q . . . . . . . . . : off =(-5.5, -5.5)/12 + (2.0, 10.0)/12
822 // . . . . . . . . Q . . . : off =(-5.5, -5.5)/12 + (8.0, 11.0)/12
823 static const float grid_size = 12.0;
824 assign_aa_cubic_constants();
825 const float4 ssd_fai = get_subpixel_support_diam_and_final_axis_importance();
826 const float2 subpixel_support_diameter = ssd_fai.xy;
827 const float2 final_axis_importance = ssd_fai.zw;
828 const float2 xy_step = float2(1.0)/grid_size * subpixel_support_diameter;
829 const float2 xy_start_offset = float2(0.5 - grid_size*0.5) * xy_step;
830 // Get the xy offset of each sample. Exploit diagonal symmetry:
831 const float2 xy_offset0 = xy_start_offset + float2(3.0, 0.0) * xy_step;
832 const float2 xy_offset1 = xy_start_offset + float2(9.0, 1.0) * xy_step;
833 const float2 xy_offset2 = xy_start_offset + float2(6.0, 2.0) * xy_step;
834 const float2 xy_offset3 = xy_start_offset + float2(1.0, 3.0) * xy_step;
835 const float2 xy_offset4 = xy_start_offset + float2(11.0, 4.0) * xy_step;
836 const float2 xy_offset5 = xy_start_offset + float2(4.0, 5.0) * xy_step;
837 // Compute subpixel weights, and exploit diagonal symmetry for speed.
838 const float3 w0 = eval_unorm_rgb_weights(xy_offset0, final_axis_importance);
839 const float3 w1 = eval_unorm_rgb_weights(xy_offset1, final_axis_importance);
840 const float3 w2 = eval_unorm_rgb_weights(xy_offset2, final_axis_importance);
841 const float3 w3 = eval_unorm_rgb_weights(xy_offset3, final_axis_importance);
842 const float3 w4 = eval_unorm_rgb_weights(xy_offset4, final_axis_importance);
843 const float3 w5 = eval_unorm_rgb_weights(xy_offset5, final_axis_importance);
844 const float3 w6 = w5.bgr;
845 const float3 w7 = w4.bgr;
846 const float3 w8 = w3.bgr;
847 const float3 w9 = w2.bgr;
848 const float3 w10 = w1.bgr;
849 const float3 w11 = w0.bgr;
850 // Get the weight sum to normalize the total to 1.0 later:
851 const float3 half_sum = w0 + w1 + w2 + w3 + w4 + w5;
852 const float3 w_sum = half_sum + half_sum.bgr;
853 const float3 w_sum_inv = float3(1.0)/w_sum;
854 // Scale the pixel-space to texture offset matrix by the pixel diameter.
855 const float2x2 true_pixel_to_tex_uv =
856 float2x2((pixel_to_tex_uv * aa_pixel_diameter));
857 // Get uv sample offsets, mirror on odd frames if directed, and exploit
858 // diagonal symmetry:
859 const float2 frame_sign = get_frame_sign(frame);
860 const float2 uv_offset0 = mul(true_pixel_to_tex_uv, xy_offset0 * frame_sign);
861 const float2 uv_offset1 = mul(true_pixel_to_tex_uv, xy_offset1 * frame_sign);
862 const float2 uv_offset2 = mul(true_pixel_to_tex_uv, xy_offset2 * frame_sign);
863 const float2 uv_offset3 = mul(true_pixel_to_tex_uv, xy_offset3 * frame_sign);
864 const float2 uv_offset4 = mul(true_pixel_to_tex_uv, xy_offset4 * frame_sign);
865 const float2 uv_offset5 = mul(true_pixel_to_tex_uv, xy_offset5 * frame_sign);
866 // Load samples, linearizing if necessary, etc.:
867 const float3 sample0 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset0).rgb;
868 const float3 sample1 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset1).rgb;
869 const float3 sample2 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset2).rgb;
870 const float3 sample3 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset3).rgb;
871 const float3 sample4 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset4).rgb;
872 const float3 sample5 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset5).rgb;
873 const float3 sample6 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset5).rgb;
874 const float3 sample7 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset4).rgb;
875 const float3 sample8 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset3).rgb;
876 const float3 sample9 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset2).rgb;
877 const float3 sample10 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset1).rgb;
878 const float3 sample11 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset0).rgb;
879 // Sum weighted samples (weight sum must equal 1.0 for each channel):
880 return w_sum_inv * (
881 w0 * sample0 + w1 * sample1 + w2 * sample2 + w3 * sample3 +
882 w4 * sample4 + w5 * sample5 + w6 * sample6 + w7 * sample7 +
883 w8 * sample8 + w9 * sample9 + w10 * sample10 + w11 * sample11);
884 }
885
tex2Daa16x(const sampler2D tex,const float2 tex_uv,const float2x2 pixel_to_tex_uv,const float frame)886 float3 tex2Daa16x(const sampler2D tex, const float2 tex_uv,
887 const float2x2 pixel_to_tex_uv, const float frame)
888 {
889 // Use a diagonally symmetric 16-superqueens pattern where no 3 points are
890 // exactly collinear.
891 // . . Q . . . . . . . . . . . . . : off =(-7.5, -7.5)/16 + (2.0, 0.0)/16
892 // . . . . . . . . . Q . . . . . . : off =(-7.5, -7.5)/16 + (9.0, 1.0)/16
893 // . . . . . . . . . . . . Q . . . : off =(-7.5, -7.5)/16 + (12.0, 2.0)/16
894 // . . . . Q . . . . . . . . . . . : off =(-7.5, -7.5)/16 + (4.0, 3.0)/16
895 // . . . . . . . . Q . . . . . . . : off =(-7.5, -7.5)/16 + (8.0, 4.0)/16
896 // . . . . . . . . . . . . . . Q . : off =(-7.5, -7.5)/16 + (14.0, 5.0)/16
897 // Q . . . . . . . . . . . . . . . : off =(-7.5, -7.5)/16 + (0.0, 6.0)/16
898 // . . . . . . . . . . Q . . . . . : off =(-7.5, -7.5)/16 + (10.0, 7.0)/16
899 // . . . . . Q . . . . . . . . . . : off =(-7.5, -7.5)/16 + (5.0, 8.0)/16
900 // . . . . . . . . . . . . . . . Q : off =(-7.5, -7.5)/16 + (15.0, 9.0)/16
901 // . Q . . . . . . . . . . . . . . : off =(-7.5, -7.5)/16 + (1.0, 10.0)/16
902 // . . . . . . . Q . . . . . . . . : off =(-7.5, -7.5)/16 + (7.0, 11.0)/16
903 // . . . . . . . . . . . Q . . . . : off =(-7.5, -7.5)/16 + (11.0, 12.0)/16
904 // . . . Q . . . . . . . . . . . . : off =(-7.5, -7.5)/16 + (3.0, 13.0)/16
905 // . . . . . . Q . . . . . . . . . : off =(-7.5, -7.5)/16 + (6.0, 14.0)/16
906 // . . . . . . . . . . . . . Q . . : off =(-7.5, -7.5)/16 + (13.0, 15.0)/16
907 static const float grid_size = 16.0;
908 assign_aa_cubic_constants();
909 const float4 ssd_fai = get_subpixel_support_diam_and_final_axis_importance();
910 const float2 subpixel_support_diameter = ssd_fai.xy;
911 const float2 final_axis_importance = ssd_fai.zw;
912 const float2 xy_step = float2(1.0)/grid_size * subpixel_support_diameter;
913 const float2 xy_start_offset = float2(0.5 - grid_size*0.5) * xy_step;
914 // Get the xy offset of each sample. Exploit diagonal symmetry:
915 const float2 xy_offset0 = xy_start_offset + float2(2.0, 0.0) * xy_step;
916 const float2 xy_offset1 = xy_start_offset + float2(9.0, 1.0) * xy_step;
917 const float2 xy_offset2 = xy_start_offset + float2(12.0, 2.0) * xy_step;
918 const float2 xy_offset3 = xy_start_offset + float2(4.0, 3.0) * xy_step;
919 const float2 xy_offset4 = xy_start_offset + float2(8.0, 4.0) * xy_step;
920 const float2 xy_offset5 = xy_start_offset + float2(14.0, 5.0) * xy_step;
921 const float2 xy_offset6 = xy_start_offset + float2(0.0, 6.0) * xy_step;
922 const float2 xy_offset7 = xy_start_offset + float2(10.0, 7.0) * xy_step;
923 // Compute subpixel weights, and exploit diagonal symmetry for speed.
924 const float3 w0 = eval_unorm_rgb_weights(xy_offset0, final_axis_importance);
925 const float3 w1 = eval_unorm_rgb_weights(xy_offset1, final_axis_importance);
926 const float3 w2 = eval_unorm_rgb_weights(xy_offset2, final_axis_importance);
927 const float3 w3 = eval_unorm_rgb_weights(xy_offset3, final_axis_importance);
928 const float3 w4 = eval_unorm_rgb_weights(xy_offset4, final_axis_importance);
929 const float3 w5 = eval_unorm_rgb_weights(xy_offset5, final_axis_importance);
930 const float3 w6 = eval_unorm_rgb_weights(xy_offset6, final_axis_importance);
931 const float3 w7 = eval_unorm_rgb_weights(xy_offset7, final_axis_importance);
932 const float3 w8 = w7.bgr;
933 const float3 w9 = w6.bgr;
934 const float3 w10 = w5.bgr;
935 const float3 w11 = w4.bgr;
936 const float3 w12 = w3.bgr;
937 const float3 w13 = w2.bgr;
938 const float3 w14 = w1.bgr;
939 const float3 w15 = w0.bgr;
940 // Get the weight sum to normalize the total to 1.0 later:
941 const float3 half_sum = w0 + w1 + w2 + w3 + w4 + w5 + w6 + w7;
942 const float3 w_sum = half_sum + half_sum.bgr;
943 const float3 w_sum_inv = float3(1.0)/(w_sum);
944 // Scale the pixel-space to texture offset matrix by the pixel diameter.
945 const float2x2 true_pixel_to_tex_uv =
946 float2x2((pixel_to_tex_uv * aa_pixel_diameter));
947 // Get uv sample offsets, mirror on odd frames if directed, and exploit
948 // diagonal symmetry:
949 const float2 frame_sign = get_frame_sign(frame);
950 const float2 uv_offset0 = mul(true_pixel_to_tex_uv, xy_offset0 * frame_sign);
951 const float2 uv_offset1 = mul(true_pixel_to_tex_uv, xy_offset1 * frame_sign);
952 const float2 uv_offset2 = mul(true_pixel_to_tex_uv, xy_offset2 * frame_sign);
953 const float2 uv_offset3 = mul(true_pixel_to_tex_uv, xy_offset3 * frame_sign);
954 const float2 uv_offset4 = mul(true_pixel_to_tex_uv, xy_offset4 * frame_sign);
955 const float2 uv_offset5 = mul(true_pixel_to_tex_uv, xy_offset5 * frame_sign);
956 const float2 uv_offset6 = mul(true_pixel_to_tex_uv, xy_offset6 * frame_sign);
957 const float2 uv_offset7 = mul(true_pixel_to_tex_uv, xy_offset7 * frame_sign);
958 // Load samples, linearizing if necessary, etc.:
959 const float3 sample0 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset0).rgb;
960 const float3 sample1 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset1).rgb;
961 const float3 sample2 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset2).rgb;
962 const float3 sample3 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset3).rgb;
963 const float3 sample4 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset4).rgb;
964 const float3 sample5 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset5).rgb;
965 const float3 sample6 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset6).rgb;
966 const float3 sample7 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset7).rgb;
967 const float3 sample8 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset7).rgb;
968 const float3 sample9 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset6).rgb;
969 const float3 sample10 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset5).rgb;
970 const float3 sample11 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset4).rgb;
971 const float3 sample12 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset3).rgb;
972 const float3 sample13 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset2).rgb;
973 const float3 sample14 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset1).rgb;
974 const float3 sample15 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset0).rgb;
975 // Sum weighted samples (weight sum must equal 1.0 for each channel):
976 return w_sum_inv * (
977 w0 * sample0 + w1 * sample1 + w2 * sample2 + w3 * sample3 +
978 w4 * sample4 + w5 * sample5 + w6 * sample6 + w7 * sample7 +
979 w8 * sample8 + w9 * sample9 + w10 * sample10 + w11 * sample11 +
980 w12 * sample12 + w13 * sample13 + w14 * sample14 + w15 * sample15);
981 }
982
tex2Daa20x(const sampler2D tex,const float2 tex_uv,const float2x2 pixel_to_tex_uv,const float frame)983 float3 tex2Daa20x(const sampler2D tex, const float2 tex_uv,
984 const float2x2 pixel_to_tex_uv, const float frame)
985 {
986 // Use a diagonally symmetric 20-superqueens pattern where no 3 points are
987 // exactly collinear and superqueens have a squared attack radius of 13.
988 // . . . . . . . Q . . . . . . . . . . . . : off =(-9.5, -9.5)/20 + (7.0, 0.0)/20
989 // . . . . . . . . . . . . . . . . Q . . . : off =(-9.5, -9.5)/20 + (16.0, 1.0)/20
990 // . . . . . . . . . . . Q . . . . . . . . : off =(-9.5, -9.5)/20 + (11.0, 2.0)/20
991 // . Q . . . . . . . . . . . . . . . . . . : off =(-9.5, -9.5)/20 + (1.0, 3.0)/20
992 // . . . . . Q . . . . . . . . . . . . . . : off =(-9.5, -9.5)/20 + (5.0, 4.0)/20
993 // . . . . . . . . . . . . . . . Q . . . . : off =(-9.5, -9.5)/20 + (15.0, 5.0)/20
994 // . . . . . . . . . . Q . . . . . . . . . : off =(-9.5, -9.5)/20 + (10.0, 6.0)/20
995 // . . . . . . . . . . . . . . . . . . . Q : off =(-9.5, -9.5)/20 + (19.0, 7.0)/20
996 // . . Q . . . . . . . . . . . . . . . . . : off =(-9.5, -9.5)/20 + (2.0, 8.0)/20
997 // . . . . . . Q . . . . . . . . . . . . . : off =(-9.5, -9.5)/20 + (6.0, 9.0)/20
998 // . . . . . . . . . . . . . Q . . . . . . : off =(-9.5, -9.5)/20 + (13.0, 10.0)/20
999 // . . . . . . . . . . . . . . . . . Q . . : off =(-9.5, -9.5)/20 + (17.0, 11.0)/20
1000 // Q . . . . . . . . . . . . . . . . . . . : off =(-9.5, -9.5)/20 + (0.0, 12.0)/20
1001 // . . . . . . . . . Q . . . . . . . . . . : off =(-9.5, -9.5)/20 + (9.0, 13.0)/20
1002 // . . . . Q . . . . . . . . . . . . . . . : off =(-9.5, -9.5)/20 + (4.0, 14.0)/20
1003 // . . . . . . . . . . . . . . Q . . . . . : off =(-9.5, -9.5)/20 + (14.0, 15.0)/20
1004 // . . . . . . . . . . . . . . . . . . Q . : off =(-9.5, -9.5)/20 + (18.0, 16.0)/20
1005 // . . . . . . . . Q . . . . . . . . . . . : off =(-9.5, -9.5)/20 + (8.0, 17.0)/20
1006 // . . . Q . . . . . . . . . . . . . . . . : off =(-9.5, -9.5)/20 + (3.0, 18.0)/20
1007 // . . . . . . . . . . . . Q . . . . . . . : off =(-9.5, -9.5)/20 + (12.0, 19.0)/20
1008 static const float grid_size = 20.0;
1009 assign_aa_cubic_constants();
1010 const float4 ssd_fai = get_subpixel_support_diam_and_final_axis_importance();
1011 const float2 subpixel_support_diameter = ssd_fai.xy;
1012 const float2 final_axis_importance = ssd_fai.zw;
1013 const float2 xy_step = float2(1.0)/grid_size * subpixel_support_diameter;
1014 const float2 xy_start_offset = float2(0.5 - grid_size*0.5) * xy_step;
1015 // Get the xy offset of each sample. Exploit diagonal symmetry:
1016 const float2 xy_offset0 = xy_start_offset + float2(7.0, 0.0) * xy_step;
1017 const float2 xy_offset1 = xy_start_offset + float2(16.0, 1.0) * xy_step;
1018 const float2 xy_offset2 = xy_start_offset + float2(11.0, 2.0) * xy_step;
1019 const float2 xy_offset3 = xy_start_offset + float2(1.0, 3.0) * xy_step;
1020 const float2 xy_offset4 = xy_start_offset + float2(5.0, 4.0) * xy_step;
1021 const float2 xy_offset5 = xy_start_offset + float2(15.0, 5.0) * xy_step;
1022 const float2 xy_offset6 = xy_start_offset + float2(10.0, 6.0) * xy_step;
1023 const float2 xy_offset7 = xy_start_offset + float2(19.0, 7.0) * xy_step;
1024 const float2 xy_offset8 = xy_start_offset + float2(2.0, 8.0) * xy_step;
1025 const float2 xy_offset9 = xy_start_offset + float2(6.0, 9.0) * xy_step;
1026 // Compute subpixel weights, and exploit diagonal symmetry for speed.
1027 const float3 w0 = eval_unorm_rgb_weights(xy_offset0, final_axis_importance);
1028 const float3 w1 = eval_unorm_rgb_weights(xy_offset1, final_axis_importance);
1029 const float3 w2 = eval_unorm_rgb_weights(xy_offset2, final_axis_importance);
1030 const float3 w3 = eval_unorm_rgb_weights(xy_offset3, final_axis_importance);
1031 const float3 w4 = eval_unorm_rgb_weights(xy_offset4, final_axis_importance);
1032 const float3 w5 = eval_unorm_rgb_weights(xy_offset5, final_axis_importance);
1033 const float3 w6 = eval_unorm_rgb_weights(xy_offset6, final_axis_importance);
1034 const float3 w7 = eval_unorm_rgb_weights(xy_offset7, final_axis_importance);
1035 const float3 w8 = eval_unorm_rgb_weights(xy_offset8, final_axis_importance);
1036 const float3 w9 = eval_unorm_rgb_weights(xy_offset9, final_axis_importance);
1037 const float3 w10 = w9.bgr;
1038 const float3 w11 = w8.bgr;
1039 const float3 w12 = w7.bgr;
1040 const float3 w13 = w6.bgr;
1041 const float3 w14 = w5.bgr;
1042 const float3 w15 = w4.bgr;
1043 const float3 w16 = w3.bgr;
1044 const float3 w17 = w2.bgr;
1045 const float3 w18 = w1.bgr;
1046 const float3 w19 = w0.bgr;
1047 // Get the weight sum to normalize the total to 1.0 later:
1048 const float3 half_sum = w0 + w1 + w2 + w3 + w4 + w5 + w6 + w7 + w8 + w9;
1049 const float3 w_sum = half_sum + half_sum.bgr;
1050 const float3 w_sum_inv = float3(1.0)/(w_sum);
1051 // Scale the pixel-space to texture offset matrix by the pixel diameter.
1052 const float2x2 true_pixel_to_tex_uv =
1053 float2x2((pixel_to_tex_uv * aa_pixel_diameter));
1054 // Get uv sample offsets, mirror on odd frames if directed, and exploit
1055 // diagonal symmetry:
1056 const float2 frame_sign = get_frame_sign(frame);
1057 const float2 uv_offset0 = mul(true_pixel_to_tex_uv, xy_offset0 * frame_sign);
1058 const float2 uv_offset1 = mul(true_pixel_to_tex_uv, xy_offset1 * frame_sign);
1059 const float2 uv_offset2 = mul(true_pixel_to_tex_uv, xy_offset2 * frame_sign);
1060 const float2 uv_offset3 = mul(true_pixel_to_tex_uv, xy_offset3 * frame_sign);
1061 const float2 uv_offset4 = mul(true_pixel_to_tex_uv, xy_offset4 * frame_sign);
1062 const float2 uv_offset5 = mul(true_pixel_to_tex_uv, xy_offset5 * frame_sign);
1063 const float2 uv_offset6 = mul(true_pixel_to_tex_uv, xy_offset6 * frame_sign);
1064 const float2 uv_offset7 = mul(true_pixel_to_tex_uv, xy_offset7 * frame_sign);
1065 const float2 uv_offset8 = mul(true_pixel_to_tex_uv, xy_offset8 * frame_sign);
1066 const float2 uv_offset9 = mul(true_pixel_to_tex_uv, xy_offset9 * frame_sign);
1067 // Load samples, linearizing if necessary, etc.:
1068 const float3 sample0 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset0).rgb;
1069 const float3 sample1 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset1).rgb;
1070 const float3 sample2 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset2).rgb;
1071 const float3 sample3 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset3).rgb;
1072 const float3 sample4 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset4).rgb;
1073 const float3 sample5 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset5).rgb;
1074 const float3 sample6 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset6).rgb;
1075 const float3 sample7 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset7).rgb;
1076 const float3 sample8 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset8).rgb;
1077 const float3 sample9 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset9).rgb;
1078 const float3 sample10 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset9).rgb;
1079 const float3 sample11 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset8).rgb;
1080 const float3 sample12 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset7).rgb;
1081 const float3 sample13 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset6).rgb;
1082 const float3 sample14 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset5).rgb;
1083 const float3 sample15 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset4).rgb;
1084 const float3 sample16 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset3).rgb;
1085 const float3 sample17 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset2).rgb;
1086 const float3 sample18 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset1).rgb;
1087 const float3 sample19 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset0).rgb;
1088 // Sum weighted samples (weight sum must equal 1.0 for each channel):
1089 return w_sum_inv * (
1090 w0 * sample0 + w1 * sample1 + w2 * sample2 + w3 * sample3 +
1091 w4 * sample4 + w5 * sample5 + w6 * sample6 + w7 * sample7 +
1092 w8 * sample8 + w9 * sample9 + w10 * sample10 + w11 * sample11 +
1093 w12 * sample12 + w13 * sample13 + w14 * sample14 + w15 * sample15 +
1094 w16 * sample16 + w17 * sample17 + w18 * sample18 + w19 * sample19);
1095 }
1096
tex2Daa24x(const sampler2D tex,const float2 tex_uv,const float2x2 pixel_to_tex_uv,const float frame)1097 float3 tex2Daa24x(const sampler2D tex, const float2 tex_uv,
1098 const float2x2 pixel_to_tex_uv, const float frame)
1099 {
1100 // Use a diagonally symmetric 24-superqueens pattern where no 3 points are
1101 // exactly collinear and superqueens have a squared attack radius of 13.
1102 // . . . . . . Q . . . . . . . . . . . . . . . . . : off =(-11.5, -11.5)/24 + (6.0, 0.0)/24
1103 // . . . . . . . . . . . . . . . . Q . . . . . . . : off =(-11.5, -11.5)/24 + (16.0, 1.0)/24
1104 // . . . . . . . . . . Q . . . . . . . . . . . . . : off =(-11.5, -11.5)/24 + (10.0, 2.0)/24
1105 // . . . . . . . . . . . . . . . . . . . . . Q . . : off =(-11.5, -11.5)/24 + (21.0, 3.0)/24
1106 // . . . . . Q . . . . . . . . . . . . . . . . . . : off =(-11.5, -11.5)/24 + (5.0, 4.0)/24
1107 // . . . . . . . . . . . . . . . Q . . . . . . . . : off =(-11.5, -11.5)/24 + (15.0, 5.0)/24
1108 // . Q . . . . . . . . . . . . . . . . . . . . . . : off =(-11.5, -11.5)/24 + (1.0, 6.0)/24
1109 // . . . . . . . . . . . Q . . . . . . . . . . . . : off =(-11.5, -11.5)/24 + (11.0, 7.0)/24
1110 // . . . . . . . . . . . . . . . . . . . Q . . . . : off =(-11.5, -11.5)/24 + (19.0, 8.0)/24
1111 // . . . . . . . . . . . . . . . . . . . . . . . Q : off =(-11.5, -11.5)/24 + (23.0, 9.0)/24
1112 // . . . Q . . . . . . . . . . . . . . . . . . . . : off =(-11.5, -11.5)/24 + (3.0, 10.0)/24
1113 // . . . . . . . . . . . . . . Q . . . . . . . . . : off =(-11.5, -11.5)/24 + (14.0, 11.0)/24
1114 // . . . . . . . . . Q . . . . . . . . . . . . . . : off =(-11.5, -11.5)/24 + (9.0, 12.0)/24
1115 // . . . . . . . . . . . . . . . . . . . . Q . . . : off =(-11.5, -11.5)/24 + (20.0, 13.0)/24
1116 // Q . . . . . . . . . . . . . . . . . . . . . . . : off =(-11.5, -11.5)/24 + (0.0, 14.0)/24
1117 // . . . . Q . . . . . . . . . . . . . . . . . . . : off =(-11.5, -11.5)/24 + (4.0, 15.0)/24
1118 // . . . . . . . . . . . . Q . . . . . . . . . . . : off =(-11.5, -11.5)/24 + (12.0, 16.0)/24
1119 // . . . . . . . . . . . . . . . . . . . . . . Q . : off =(-11.5, -11.5)/24 + (22.0, 17.0)/24
1120 // . . . . . . . . Q . . . . . . . . . . . . . . . : off =(-11.5, -11.5)/24 + (8.0, 18.0)/24
1121 // . . . . . . . . . . . . . . . . . . Q . . . . . : off =(-11.5, -11.5)/24 + (18.0, 19.0)/24
1122 // . . Q . . . . . . . . . . . . . . . . . . . . . : off =(-11.5, -11.5)/24 + (2.0, 20.0)/24
1123 // . . . . . . . . . . . . . Q . . . . . . . . . . : off =(-11.5, -11.5)/24 + (13.0, 21.0)/24
1124 // . . . . . . . Q . . . . . . . . . . . . . . . . : off =(-11.5, -11.5)/24 + (7.0, 22.0)/24
1125 // . . . . . . . . . . . . . . . . . Q . . . . . . : off =(-11.5, -11.5)/24 + (17.0, 23.0)/24
1126 static const float grid_size = 24.0;
1127 assign_aa_cubic_constants();
1128 const float4 ssd_fai = get_subpixel_support_diam_and_final_axis_importance();
1129 const float2 subpixel_support_diameter = ssd_fai.xy;
1130 const float2 final_axis_importance = ssd_fai.zw;
1131 const float2 xy_step = float2(1.0)/grid_size * subpixel_support_diameter;
1132 const float2 xy_start_offset = float2(0.5 - grid_size*0.5) * xy_step;
1133 // Get the xy offset of each sample. Exploit diagonal symmetry:
1134 const float2 xy_offset0 = xy_start_offset + float2(6.0, 0.0) * xy_step;
1135 const float2 xy_offset1 = xy_start_offset + float2(16.0, 1.0) * xy_step;
1136 const float2 xy_offset2 = xy_start_offset + float2(10.0, 2.0) * xy_step;
1137 const float2 xy_offset3 = xy_start_offset + float2(21.0, 3.0) * xy_step;
1138 const float2 xy_offset4 = xy_start_offset + float2(5.0, 4.0) * xy_step;
1139 const float2 xy_offset5 = xy_start_offset + float2(15.0, 5.0) * xy_step;
1140 const float2 xy_offset6 = xy_start_offset + float2(1.0, 6.0) * xy_step;
1141 const float2 xy_offset7 = xy_start_offset + float2(11.0, 7.0) * xy_step;
1142 const float2 xy_offset8 = xy_start_offset + float2(19.0, 8.0) * xy_step;
1143 const float2 xy_offset9 = xy_start_offset + float2(23.0, 9.0) * xy_step;
1144 const float2 xy_offset10 = xy_start_offset + float2(3.0, 10.0) * xy_step;
1145 const float2 xy_offset11 = xy_start_offset + float2(14.0, 11.0) * xy_step;
1146 // Compute subpixel weights, and exploit diagonal symmetry for speed.
1147 const float3 w0 = eval_unorm_rgb_weights(xy_offset0, final_axis_importance);
1148 const float3 w1 = eval_unorm_rgb_weights(xy_offset1, final_axis_importance);
1149 const float3 w2 = eval_unorm_rgb_weights(xy_offset2, final_axis_importance);
1150 const float3 w3 = eval_unorm_rgb_weights(xy_offset3, final_axis_importance);
1151 const float3 w4 = eval_unorm_rgb_weights(xy_offset4, final_axis_importance);
1152 const float3 w5 = eval_unorm_rgb_weights(xy_offset5, final_axis_importance);
1153 const float3 w6 = eval_unorm_rgb_weights(xy_offset6, final_axis_importance);
1154 const float3 w7 = eval_unorm_rgb_weights(xy_offset7, final_axis_importance);
1155 const float3 w8 = eval_unorm_rgb_weights(xy_offset8, final_axis_importance);
1156 const float3 w9 = eval_unorm_rgb_weights(xy_offset9, final_axis_importance);
1157 const float3 w10 = eval_unorm_rgb_weights(xy_offset10, final_axis_importance);
1158 const float3 w11 = eval_unorm_rgb_weights(xy_offset11, final_axis_importance);
1159 const float3 w12 = w11.bgr;
1160 const float3 w13 = w10.bgr;
1161 const float3 w14 = w9.bgr;
1162 const float3 w15 = w8.bgr;
1163 const float3 w16 = w7.bgr;
1164 const float3 w17 = w6.bgr;
1165 const float3 w18 = w5.bgr;
1166 const float3 w19 = w4.bgr;
1167 const float3 w20 = w3.bgr;
1168 const float3 w21 = w2.bgr;
1169 const float3 w22 = w1.bgr;
1170 const float3 w23 = w0.bgr;
1171 // Get the weight sum to normalize the total to 1.0 later:
1172 const float3 half_sum = w0 + w1 + w2 + w3 + w4 +
1173 w5 + w6 + w7 + w8 + w9 + w10 + w11;
1174 const float3 w_sum = half_sum + half_sum.bgr;
1175 const float3 w_sum_inv = float3(1.0)/(w_sum);
1176 // Scale the pixel-space to texture offset matrix by the pixel diameter.
1177 const float2x2 true_pixel_to_tex_uv =
1178 float2x2((pixel_to_tex_uv * aa_pixel_diameter));
1179 // Get uv sample offsets, mirror on odd frames if directed, and exploit
1180 // diagonal symmetry:
1181 const float2 frame_sign = get_frame_sign(frame);
1182 const float2 uv_offset0 = mul(true_pixel_to_tex_uv, xy_offset0 * frame_sign);
1183 const float2 uv_offset1 = mul(true_pixel_to_tex_uv, xy_offset1 * frame_sign);
1184 const float2 uv_offset2 = mul(true_pixel_to_tex_uv, xy_offset2 * frame_sign);
1185 const float2 uv_offset3 = mul(true_pixel_to_tex_uv, xy_offset3 * frame_sign);
1186 const float2 uv_offset4 = mul(true_pixel_to_tex_uv, xy_offset4 * frame_sign);
1187 const float2 uv_offset5 = mul(true_pixel_to_tex_uv, xy_offset5 * frame_sign);
1188 const float2 uv_offset6 = mul(true_pixel_to_tex_uv, xy_offset6 * frame_sign);
1189 const float2 uv_offset7 = mul(true_pixel_to_tex_uv, xy_offset7 * frame_sign);
1190 const float2 uv_offset8 = mul(true_pixel_to_tex_uv, xy_offset8 * frame_sign);
1191 const float2 uv_offset9 = mul(true_pixel_to_tex_uv, xy_offset9 * frame_sign);
1192 const float2 uv_offset10 = mul(true_pixel_to_tex_uv, xy_offset10 * frame_sign);
1193 const float2 uv_offset11 = mul(true_pixel_to_tex_uv, xy_offset11 * frame_sign);
1194 // Load samples, linearizing if necessary, etc.:
1195 const float3 sample0 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset0).rgb;
1196 const float3 sample1 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset1).rgb;
1197 const float3 sample2 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset2).rgb;
1198 const float3 sample3 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset3).rgb;
1199 const float3 sample4 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset4).rgb;
1200 const float3 sample5 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset5).rgb;
1201 const float3 sample6 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset6).rgb;
1202 const float3 sample7 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset7).rgb;
1203 const float3 sample8 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset8).rgb;
1204 const float3 sample9 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset9).rgb;
1205 const float3 sample10 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset10).rgb;
1206 const float3 sample11 = tex2Daa_tiled_linearize(tex, tex_uv + uv_offset11).rgb;
1207 const float3 sample12 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset11).rgb;
1208 const float3 sample13 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset10).rgb;
1209 const float3 sample14 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset9).rgb;
1210 const float3 sample15 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset8).rgb;
1211 const float3 sample16 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset7).rgb;
1212 const float3 sample17 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset6).rgb;
1213 const float3 sample18 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset5).rgb;
1214 const float3 sample19 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset4).rgb;
1215 const float3 sample20 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset3).rgb;
1216 const float3 sample21 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset2).rgb;
1217 const float3 sample22 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset1).rgb;
1218 const float3 sample23 = tex2Daa_tiled_linearize(tex, tex_uv - uv_offset0).rgb;
1219 // Sum weighted samples (weight sum must equal 1.0 for each channel):
1220 return w_sum_inv * (
1221 w0 * sample0 + w1 * sample1 + w2 * sample2 + w3 * sample3 +
1222 w4 * sample4 + w5 * sample5 + w6 * sample6 + w7 * sample7 +
1223 w8 * sample8 + w9 * sample9 + w10 * sample10 + w11 * sample11 +
1224 w12 * sample12 + w13 * sample13 + w14 * sample14 + w15 * sample15 +
1225 w16 * sample16 + w17 * sample17 + w18 * sample18 + w19 * sample19 +
1226 w20 * sample20 + w21 * sample21 + w22 * sample22 + w23 * sample23);
1227 }
1228
tex2Daa_debug_16x_regular(const sampler2D tex,const float2 tex_uv,const float2x2 pixel_to_tex_uv,const float frame)1229 float3 tex2Daa_debug_16x_regular(const sampler2D tex, const float2 tex_uv,
1230 const float2x2 pixel_to_tex_uv, const float frame)
1231 {
1232 // Sample on a regular 4x4 grid. This is mainly for testing.
1233 static const float grid_size = 4.0;
1234 assign_aa_cubic_constants();
1235 const float4 ssd_fai = get_subpixel_support_diam_and_final_axis_importance();
1236 const float2 subpixel_support_diameter = ssd_fai.xy;
1237 const float2 final_axis_importance = ssd_fai.zw;
1238 const float2 xy_step = float2(1.0)/grid_size * subpixel_support_diameter;
1239 const float2 xy_start_offset = float2(0.5 - grid_size*0.5) * xy_step;
1240 // Get the xy offset of each sample:
1241 const float2 xy_offset0 = xy_start_offset + float2(0.0, 0.0) * xy_step;
1242 const float2 xy_offset1 = xy_start_offset + float2(1.0, 0.0) * xy_step;
1243 const float2 xy_offset2 = xy_start_offset + float2(2.0, 0.0) * xy_step;
1244 const float2 xy_offset3 = xy_start_offset + float2(3.0, 0.0) * xy_step;
1245 const float2 xy_offset4 = xy_start_offset + float2(0.0, 1.0) * xy_step;
1246 const float2 xy_offset5 = xy_start_offset + float2(1.0, 1.0) * xy_step;
1247 const float2 xy_offset6 = xy_start_offset + float2(2.0, 1.0) * xy_step;
1248 const float2 xy_offset7 = xy_start_offset + float2(3.0, 1.0) * xy_step;
1249 // Compute subpixel weights, and exploit diagonal symmetry for speed.
1250 // (We can't exploit vertical or horizontal symmetry due to uncertain
1251 // subpixel offsets. We could fix that by rotating xy offsets with the
1252 // subpixel structure, but...no.)
1253 const float3 w0 = eval_unorm_rgb_weights(xy_offset0, final_axis_importance);
1254 const float3 w1 = eval_unorm_rgb_weights(xy_offset1, final_axis_importance);
1255 const float3 w2 = eval_unorm_rgb_weights(xy_offset2, final_axis_importance);
1256 const float3 w3 = eval_unorm_rgb_weights(xy_offset3, final_axis_importance);
1257 const float3 w4 = eval_unorm_rgb_weights(xy_offset4, final_axis_importance);
1258 const float3 w5 = eval_unorm_rgb_weights(xy_offset5, final_axis_importance);
1259 const float3 w6 = eval_unorm_rgb_weights(xy_offset6, final_axis_importance);
1260 const float3 w7 = eval_unorm_rgb_weights(xy_offset7, final_axis_importance);
1261 const float3 w8 = w7.bgr;
1262 const float3 w9 = w6.bgr;
1263 const float3 w10 = w5.bgr;
1264 const float3 w11 = w4.bgr;
1265 const float3 w12 = w3.bgr;
1266 const float3 w13 = w2.bgr;
1267 const float3 w14 = w1.bgr;
1268 const float3 w15 = w0.bgr;
1269 // Get the weight sum to normalize the total to 1.0 later:
1270 const float3 half_sum = w0 + w1 + w2 + w3 + w4 + w5 + w6 + w7;
1271 const float3 w_sum = half_sum + half_sum.bgr;
1272 const float3 w_sum_inv = float3(1.0)/(w_sum);
1273 // Scale the pixel-space to texture offset matrix by the pixel diameter.
1274 const float2x2 true_pixel_to_tex_uv =
1275 float2x2((pixel_to_tex_uv * aa_pixel_diameter));
1276 // Get uv sample offsets, taking advantage of row alignment:
1277 const float2 uv_step_x = mul(true_pixel_to_tex_uv, float2(xy_step.x, 0.0));
1278 const float2 uv_step_y = mul(true_pixel_to_tex_uv, float2(0.0, xy_step.y));
1279 const float2 uv_offset0 = -1.5 * (uv_step_x + uv_step_y);
1280 const float2 sample0_uv = tex_uv + uv_offset0;
1281 const float2 sample4_uv = sample0_uv + uv_step_y;
1282 const float2 sample8_uv = sample0_uv + uv_step_y * 2.0;
1283 const float2 sample12_uv = sample0_uv + uv_step_y * 3.0;
1284 // Load samples, linearizing if necessary, etc.:
1285 const float3 sample0 = tex2Daa_tiled_linearize(tex, sample0_uv).rgb;
1286 const float3 sample1 = tex2Daa_tiled_linearize(tex, sample0_uv + uv_step_x).rgb;
1287 const float3 sample2 = tex2Daa_tiled_linearize(tex, sample0_uv + uv_step_x * 2.0).rgb;
1288 const float3 sample3 = tex2Daa_tiled_linearize(tex, sample0_uv + uv_step_x * 3.0).rgb;
1289 const float3 sample4 = tex2Daa_tiled_linearize(tex, sample4_uv).rgb;
1290 const float3 sample5 = tex2Daa_tiled_linearize(tex, sample4_uv + uv_step_x).rgb;
1291 const float3 sample6 = tex2Daa_tiled_linearize(tex, sample4_uv + uv_step_x * 2.0).rgb;
1292 const float3 sample7 = tex2Daa_tiled_linearize(tex, sample4_uv + uv_step_x * 3.0).rgb;
1293 const float3 sample8 = tex2Daa_tiled_linearize(tex, sample8_uv).rgb;
1294 const float3 sample9 = tex2Daa_tiled_linearize(tex, sample8_uv + uv_step_x).rgb;
1295 const float3 sample10 = tex2Daa_tiled_linearize(tex, sample8_uv + uv_step_x * 2.0).rgb;
1296 const float3 sample11 = tex2Daa_tiled_linearize(tex, sample8_uv + uv_step_x * 3.0).rgb;
1297 const float3 sample12 = tex2Daa_tiled_linearize(tex, sample12_uv).rgb;
1298 const float3 sample13 = tex2Daa_tiled_linearize(tex, sample12_uv + uv_step_x).rgb;
1299 const float3 sample14 = tex2Daa_tiled_linearize(tex, sample12_uv + uv_step_x * 2.0).rgb;
1300 const float3 sample15 = tex2Daa_tiled_linearize(tex, sample12_uv + uv_step_x * 3.0).rgb;
1301 // Sum weighted samples (weight sum must equal 1.0 for each channel):
1302 return w_sum_inv * (
1303 w0 * sample0 + w1 * sample1 + w2 * sample2 + w3 * sample3 +
1304 w4 * sample4 + w5 * sample5 + w6 * sample6 + w7 * sample7 +
1305 w8 * sample8 + w9 * sample9 + w10 * sample10 + w11 * sample11 +
1306 w12 * sample12 + w13 * sample13 + w14 * sample14 + w15 * sample15);
1307 }
1308
tex2Daa_debug_dynamic(const sampler2D tex,const float2 tex_uv,const float2x2 pixel_to_tex_uv,const float frame)1309 float3 tex2Daa_debug_dynamic(const sampler2D tex, const float2 tex_uv,
1310 const float2x2 pixel_to_tex_uv, const float frame)
1311 {
1312 // This function is for testing only: Use an NxN grid with dynamic weights.
1313 static const int grid_size = 8;
1314 assign_aa_cubic_constants();
1315 const float4 ssd_fai = get_subpixel_support_diam_and_final_axis_importance();
1316 const float2 subpixel_support_diameter = ssd_fai.xy;
1317 const float2 final_axis_importance = ssd_fai.zw;
1318 const float grid_radius_in_samples = (float(grid_size) - 1.0)/2.0;
1319 const float2 filter_space_offset_step =
1320 subpixel_support_diameter/float2(grid_size);
1321 const float2 sample0_filter_space_offset =
1322 -grid_radius_in_samples * filter_space_offset_step;
1323 // Compute xy sample offsets and subpixel weights:
1324 float3 weights[64]; // grid_size * grid_size
1325 float3 weight_sum = float3(0.0, 0.0, 0.0);
1326 for(int i = 0; i < grid_size; ++i)
1327 {
1328 for(int j = 0; j < grid_size; ++j)
1329 {
1330 // Weights based on xy distances:
1331 const float2 offset = sample0_filter_space_offset +
1332 float2(j, i) * filter_space_offset_step;
1333 const float3 weight = eval_unorm_rgb_weights(offset, final_axis_importance);
1334 weights[i*grid_size + j] = weight;
1335 weight_sum += weight;
1336 }
1337 }
1338 // Get uv offset vectors along x and y directions:
1339 const float2x2 true_pixel_to_tex_uv =
1340 float2x2((pixel_to_tex_uv * aa_pixel_diameter));
1341 const float2 uv_offset_step_x = mul(true_pixel_to_tex_uv,
1342 float2(filter_space_offset_step.x, 0.0));
1343 const float2 uv_offset_step_y = mul(true_pixel_to_tex_uv,
1344 float2(0.0, filter_space_offset_step.y));
1345 // Get a starting sample location:
1346 const float2 sample0_uv_offset = -grid_radius_in_samples *
1347 (uv_offset_step_x + uv_offset_step_y);
1348 const float2 sample0_uv = tex_uv + sample0_uv_offset;
1349 // Load, weight, and sum [linearized] samples:
1350 float3 sum = float3(0.0, 0.0, 0.0);
1351 const float3 weight_sum_inv = float3(1.0)/weight_sum;
1352 for(int i = 0; i < grid_size; ++i)
1353 {
1354 const float2 row_i_first_sample_uv =
1355 sample0_uv + i * uv_offset_step_y;
1356 for(int j = 0; j < grid_size; ++j)
1357 {
1358 const float2 sample_uv =
1359 row_i_first_sample_uv + j * uv_offset_step_x;
1360 sum += weights[i*grid_size + j] *
1361 tex2Daa_tiled_linearize(tex, sample_uv).rgb;
1362 }
1363 }
1364 return sum * weight_sum_inv;
1365 }
1366
1367
1368 /////////////////////// ANTIALIASING CODEPATH SELECTION //////////////////////
1369
tex2Daa(const sampler2D tex,const float2 tex_uv,const float2x2 pixel_to_tex_uv,const float frame)1370 inline float3 tex2Daa(const sampler2D tex, const float2 tex_uv,
1371 const float2x2 pixel_to_tex_uv, const float frame)
1372 {
1373 // Statically switch between antialiasing modes/levels:
1374 return (aa_level < 0.5) ? tex2D_linearize(tex, tex_uv).rgb :
1375 (aa_level < 3.5) ? tex2Daa_subpixel_weights_only(
1376 tex, tex_uv, pixel_to_tex_uv) :
1377 (aa_level < 4.5) ? tex2Daa4x(tex, tex_uv, pixel_to_tex_uv, frame) :
1378 (aa_level < 5.5) ? tex2Daa5x(tex, tex_uv, pixel_to_tex_uv, frame) :
1379 (aa_level < 6.5) ? tex2Daa6x(tex, tex_uv, pixel_to_tex_uv, frame) :
1380 (aa_level < 7.5) ? tex2Daa7x(tex, tex_uv, pixel_to_tex_uv, frame) :
1381 (aa_level < 11.5) ? tex2Daa8x(tex, tex_uv, pixel_to_tex_uv, frame) :
1382 (aa_level < 15.5) ? tex2Daa12x(tex, tex_uv, pixel_to_tex_uv, frame) :
1383 (aa_level < 19.5) ? tex2Daa16x(tex, tex_uv, pixel_to_tex_uv, frame) :
1384 (aa_level < 23.5) ? tex2Daa20x(tex, tex_uv, pixel_to_tex_uv, frame) :
1385 (aa_level < 253.5) ? tex2Daa24x(tex, tex_uv, pixel_to_tex_uv, frame) :
1386 (aa_level < 254.5) ? tex2Daa_debug_16x_regular(
1387 tex, tex_uv, pixel_to_tex_uv, frame) :
1388 tex2Daa_debug_dynamic(tex, tex_uv, pixel_to_tex_uv, frame);
1389 }
1390
1391
1392 #endif // TEX2DANTIALIAS_H
1393
1394