I am trying to implement this formula to generate bump but I am facing some issue. The result doesn't look the same it's much darker.
Here is my result (without same parameters) but it is much darker and I don't get why.
And here is the associated code.
// randx, randy and frequencies are array with some random values for each sin wave.
for (int x = 0; x < _width; ++x)
{
for (int y = 0; y < _height; ++y)
{
float color = 0.0f;
for (int i = 0; i < _iterations; ++i)
{
val += Mathf.Sin(Mathf.Sqrt(Mathf.Pow(x - randx[i], 2.0f) + Mathf.Pow(y - randy[i], 2.0f)) * 1.0f / (2.08f + 5.0f * frequencies[i]));
}
color /= (float)_iterations;
}
}
Any idea why I am getting this result ?
Thanks a lot !
EDIT: Thanks to @trichoplax it works by doing this.
float tmp = Mathf.Sin(Mathf.Sqrt(Mathf.Pow(x - randx[i], 2.0f) + Mathf.Pow(y - randy[i], 2.0f)) * 1.0f / (2.08f + 5.0f * frequencies[i]));
tmp = tmp * 0.5f + 0.5f;
val += tmp;
(foo * foo)
to be a lot faster thanpow(foo, 2.0f)
; if your data is organized row by row (as opposed to column by column), you should swap the for loops to traverse data in a more coherent order. $\endgroup$