- float n[4];
- float t[4];
- for (size_t i = 0; i < 4; ++i) {
- t[i] = 0.6f - dot(offset[i], offset[i]);
- if (t[i] < 0.0f) {
- n[i] = 0.0f;
- } else {
- t[i] *= t[i];
- n[i] = t[i] * t[i] * dot(Grad(corner[i]), offset[i]);
- }
+
+ float n = 0.0f;
+
+ // 0
+ float t = 0.6f - dot(offset[0], offset[0]);
+ if (t > 0.0f) {
+ t *= t;
+ int corner = Perm12(index[0] + Perm(index[1] + Perm(index[2])));
+ n += t * t * dot(Grad(corner), offset[0]);
+ }
+
+ // 1
+ t = 0.6f - dot(offset[1], offset[1]);
+ if (t > 0.0f) {
+ t *= t;
+ int corner = Perm12(index[0] + int(second.x) + Perm(index[1] + int(second.y) + Perm(index[2] + int(second.z))));
+ n += t * t * dot(Grad(corner), offset[1]);
+ }
+
+ // 2
+ t = 0.6f - dot(offset[2], offset[2]);
+ if (t > 0.0f) {
+ t *= t;
+ int corner = Perm12(index[0] + int(third.x) + Perm(index[1] + int(third.y) + Perm(index[2] + int(third.z))));
+ n += t * t * dot(Grad(corner), offset[2]);
+ }
+
+ // 3
+ t = 0.6f - dot(offset[3], offset[3]);
+ if (t > 0.0f) {
+ t *= t;
+ int corner = Perm12(index[0] + 1 + Perm(index[1] + 1 + Perm(index[2] + 1)));
+ n += t * t * dot(Grad(corner), offset[3]);