Changeset 3720


Ignore:
Timestamp:
Dec 23, 2014, 1:23:12 PM (7 years ago)
Author:
sam
Message:

simplex: optimisation; reduce the number of matrix multiplications.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/demos/test/simplex.cpp

    r3718 r3720  
    2323
    2424    int const period = 10;
    25     float const zoom = 0.03f;
     25    float const zoom = 0.02f;
    2626
    2727    /* Create some gradients */
     
    4242    for (int i = 0; i < size.x; ++i)
    4343    {
    44         float p = 0.5f + 0.5f * s.Interp(zoom * vec2(i, j));
     44        float p = 0.5f * s.Interp(zoom * vec2(i, j));
    4545#if 0
    46         for (int k = 2; k < 32; k *= 2)
     46        for (int k = 2; k < 128; k *= 2)
    4747            p += 0.5f / k * s.Interp(zoom * k * vec2(i, j));
    4848#endif
    49         data[i][j] = vec4(saturate(p), 0.f, 0.f, 1.f);
     49        data[i][j] = vec4(saturate(0.5f + p), 0.f, 0.f, 1.f);
    5050    }
    5151
  • trunk/src/lol/math/simplex_interpolator.h

    r3719 r3720  
    5252
    5353        // Resetting decimal point in regular orthonormal coordinates
    54         // pos = m_base * pos;
     54        pos = m_base * pos;
    5555
    5656        return this->LastInterp(origin, pos, index_order);
     
    5959protected:
    6060
    61     inline float LastInterp(vec_t<int, N> & origin,
     61    inline float LastInterp(vec_t<int, N> origin,
    6262                            vec_t<float, N> const & pos,
    63                             vec_t<int, N> index_order) const
     63                            vec_t<int, N> const & index_order) const
    6464    {
    65         // “corner” will traverse the simplex along its edges
     65        // “corner” will traverse the simplex along its edges in
     66        // orthonormal coordinates
    6667        vec_t<float, N> corner(0);
    6768        float result = 0;
     
    6970        for (int i = 0; i < N + 1; ++i)
    7071        {
    71             float dist = 0.5f - 0.75f * sqlength(this->m_base * (pos - corner));
     72            vec_t<float, N> const delta = pos - corner;
    7273            vec_t<float, N> const &gradient = this->m_gradients[origin];
    7374
     75            // FIXME: where does the 0.75 come from?
     76            float dist = 0.5f - 0.75f * sqlength(delta);
    7477            if (dist > 0)
    75                 result += dist * dist * dist * dist * dot(gradient, this->m_base * (pos - corner));
     78            {
     79                dist *= dist;
     80                result += dist * dist * dot(gradient, delta);
     81            }
    7682
    7783            if (i < N)
    7884            {
    79                 corner[index_order[i]] += 1;
    80                 origin[index_order[i]] = this->Mod(origin[index_order[i]] + 1, index_order[i]);
     85                corner += m_base[index_order[i]];
     86                origin[index_order[i]] = this->Mod(origin[index_order[i]] + 1,
     87                                                   index_order[i]);
    8188            }
    8289        }
     
    8491        // Approximative scaling factor “100” seems to work well
    8592        // ie. gives a max value of 1 (a bit more in fact) for normed gradients
    86         return result * 100;
     93        // FIXME: another paper uses the value 70 for dimension 2, 32 for
     94        // dimension 3, and 27 for dimension 4; find where this comes from.
     95        return result * 100.f;
    8796    }
    8897
Note: See TracChangeset for help on using the changeset viewer.