- Home /
Question by
ausLancaster · Aug 03, 2017 at 08:21 AM ·
shaderprocedural generationperlin noisehash
Perlin Noise not working properly when using offset
I'm trying to write a shader that uses Perlin Noise. I am using the function noise with an offset that will change with time. All good so far:
float offset = 0;
float noise1 = noise((IN.worldPos.xz + offset)) + 0.5;
return noise1*float3(1, 1, 1);
However, when the offset exceeds around 500 the noise doesn't work properly.
float offset = 500;
float noise1 = noise((IN.worldPos.xz + offset)) + 0.5;
return noise1*float3(1, 1, 1);
Why is this? Here is the noise and hash function I am using:
float2 hash(float2 x)
{
const float2 k = float2(0.3183099, 0.3678794);
x = x*k + k.yx;
return -1.0 + 2.0*frac(16.0 * k*frac(x.x*x.y*(x.x + x.y)));
}
float noise(in float2 p)
{
float2 i = floor(p);
float2 f = frac(p);
float2 u = f*f*(3.0 - 2.0*f);
return lerp(lerp(dot(hash(i + float2(0.0, 0.0)), f - float2(0.0, 0.0)),
dot(hash(i + float2(1.0, 0.0)), f - float2(1.0, 0.0)), u.x),
lerp(dot(hash(i + float2(0.0, 1.0)), f - float2(0.0, 1.0)),
dot(hash(i + float2(1.0, 1.0)), f - float2(1.0, 1.0)), u.x), u.y);
}
noise-normal-small.png
(128.2 kB)
noise-buggy-small.png
(106.4 kB)
Comment
Your answer
Follow this Question
Related Questions
Adding rivers to procedural generated 2D map 1 Answer
Procedural Shader Cost/Draw Calls 1 Answer
Better perlin noise map generation. 0 Answers
Procedural Generation in Unity 0 Answers
Unexpected period length with Unity Mathematics pnoise method 0 Answers