42inline float areaOrtho(
float p,
float d,
float offset)
47 float a1 = p + 0.5f + offset;
58 coverage = (1.0f - t) * 0.5f;
70inline void calcAreaOrtho(
int d1,
int d2,
int e1,
int e2,
float offset,
float& r,
float& g)
76 float totalDist = float(d1 + d2);
80 if (totalDist < 1e-5f)
89 float subpix = offset;
94 float centerDist = (p1 + p2);
95 if (centerDist == 0.0f)
99 float a = p1 / centerDist;
100 float b = p2 / centerDist;
104 float crossModA = 1.0f;
105 float crossModB = 1.0f;
109 crossModA = 0.5f + subpix;
111 crossModB = 0.5f - subpix;
115 float smooth1 = 1.0f - a;
116 float smooth2 = 1.0f - b;
119 r = smooth1 * crossModA * 0.5f;
120 g = smooth2 * crossModB * 0.5f;
123 r = std::fmax(0.0f, std::fmin(1.0f, r));
124 g = std::fmax(0.0f, std::fmin(1.0f, g));
131 static const float offsets[7] = {0.0f, -0.25f, 0.25f, -0.125f, 0.125f, -0.375f, 0.375f};
163 const int patternsPerRow = 5;
168 int baseY = subpixIdx * subtexSize * patternsPerRow;
170 for (
int e1 = 0; e1 < patternsPerRow; e1++) {
171 for (
int e2 = 0; e2 < patternsPerRow; e2++) {
172 int patX = e2 * subtexSize;
173 int patY = baseY + e1 * subtexSize;
187 out[idx + 0] =
static_cast<unsigned char>(r * 255.0f + 0.5f);
188 out[idx + 1] =
static_cast<unsigned char>(g * 255.0f + 0.5f);
198 const int diagBaseX = patternsPerRow * subtexSize;
202 int baseY = subpixIdx * subtexSize * patternsPerRow;
204 for (
int e1 = 0; e1 < patternsPerRow; e1++) {
205 for (
int e2 = 0; e2 < patternsPerRow; e2++) {
206 int patX = diagBaseX + e2 * subtexSize;
207 int patY = baseY + e1 * subtexSize;
220 float totalDist = float(d1 + d2);
221 float r = 0.0f, g = 0.0f;
222 if (totalDist > 0.0f) {
223 r = (1.0f - float(d1) / totalDist) * 0.5f;
224 g = (1.0f - float(d2) / totalDist) * 0.5f;
228 r *= (0.5f + offset);
230 g *= (0.5f - offset);
232 r = std::fmax(0.0f, std::fmin(1.0f, r));
233 g = std::fmax(0.0f, std::fmin(1.0f, g));
237 out[idx + 0] =
static_cast<unsigned char>(r * 255.0f + 0.5f);
238 out[idx + 1] =
static_cast<unsigned char>(g * 255.0f + 0.5f);
static constexpr int SMAA_AREATEX_MAX_DISTANCE
Number of orthogonal edge patterns (5x4 = 20 actually, but the original implementation uses a 5x5 gri...
Definition SMAAAreaTex.h:28
static constexpr int SMAA_AREATEX_SUBTEX_SIZE
Definition SMAAAreaTex.h:31
void generateAreaTex(unsigned char *out)
Generate the SMAA area texture into a caller-provided buffer.
Definition SMAAAreaTex.h:139
static constexpr int SMAA_AREATEX_WIDTH
Definition SMAAAreaTex.h:22
static constexpr int SMAA_AREATEX_ORTHO_PATTERNS
Definition SMAAAreaTex.h:30
static constexpr int SMAA_AREATEX_SUBTEX_COUNT
Definition SMAAAreaTex.h:29
static constexpr int SMAA_AREATEX_HEIGHT
Definition SMAAAreaTex.h:23
static constexpr int SMAA_AREATEX_PITCH
Definition SMAAAreaTex.h:24
Definition SMAAAreaTex.h:37
float areaOrtho(float p, float d, float offset)
Smoothing function used by the area calculation.
Definition SMAAAreaTex.h:42
float subtexOffset(int idx)
Map sub-pixel index [0..6] to sub-pixel offset value.
Definition SMAAAreaTex.h:128
void calcAreaOrtho(int d1, int d2, int e1, int e2, float offset, float &r, float &g)
Compute the area for a specific orthogonal edge configuration.
Definition SMAAAreaTex.h:70