glsl で使える2Dシームレスノイズの関数貼っておきます。特に何の変哲もないノイズですが。
下記のような感じのノイズが生成できます。
ソースです。GenerateSeamlessNoise(vec2 position, float time) だけ使えばOK。
const float PI = 3.1415926;
float GetInterpolatedValue(float value_a, float value_b, float x)
{
float f = (1.0 - cos(x * PI)) * 0.5;
return value_a * (1.0 - f) + value_b * f;
}
float GetRandomValue(vec2 sead)
{
return fract(sin(dot(sead, vec2(12.9898, 78.233))) * 43758.5453);
}
float GetInterpolatedRandomValue(vec2 sead)
{
vec2 integer_part = floor(sead);
vec2 fractional_part = fract(sead);
vec4 value = vec4(
GetRandomValue(vec2(integer_part.x, integer_part.y)),
GetRandomValue(vec2(integer_part.x + 1.0, integer_part.y)),
GetRandomValue(vec2(integer_part.x, integer_part.y + 1.0)),
GetRandomValue(vec2(integer_part.x + 1.0, integer_part.y + 1.0)));
return GetInterpolatedValue(
GetInterpolatedValue(value.x, value.y, fractional_part.x),
GetInterpolatedValue(value.z, value.w, fractional_part.x),
fractional_part.y);
}
float GenerateNoise(vec2 position)
{
const int oct = 8;
const float per = 0.5;
float result = 0.0;
for (int i = 0; i < oct; ++i)
{
float freq = pow(2.0, float(i));
float amplitude = pow(per, float(oct - i));
result += GetInterpolatedRandomValue(vec2(position.x / freq, position.y / freq)) * amplitude;
}
return result;
}
float GenerateSeamlessNoise(vec2 noise_position, vec2 position_variation_sead, vec2 amplitude_variation_sead)
{
float result = GenerateNoise(vec2(noise_position.x, noise_position.y))
* amplitude_variation_sead.x * amplitude_variation_sead.y;
result += GenerateNoise(vec2(noise_position.x, noise_position.y + position_variation_sead.y))
* amplitude_variation_sead.x * (1.0 - amplitude_variation_sead.y);
result += GenerateNoise(vec2(noise_position.x + position_variation_sead.x, noise_position.y))
* (1.0 - amplitude_variation_sead.x) * amplitude_variation_sead.y;
result += GenerateNoise(vec2(noise_position.x + position_variation_sead.x, noise_position.y + position_variation_sead.y))
* (1.0 - amplitude_variation_sead.x) * (1.0 - amplitude_variation_sead.y);
return result;
}
float GenerateSeamlessNoise(vec2 position, float time)
{
return GenerateSeamlessNoise(
position,
vec2(time, time),
vec2(0.3, 0.3));
}