garrysmod
garrysmod copied to clipboard
Add Coherent Noise Utility Functions
Useful in animations that require natural looking movement. The seeds for the noise functions should be offsets with respect to time, for example:
local vec1 = util.NoiseVector( time )
local vec2 = util.NoiseVector( time + 88 ) -- 88 would be the "seed"
I don't understand this one
The util.Noise function allows you to gernerate the same result given a specific input. The util.CoherentNoise function uses this to create a cubic hermite spline with random positions and tangents using the floor and ceil of its input as the seeds and then interpolates between them using the fractional component of its input. For example:
print( util.Noise( 6 ), util.Noise( 6 ) ) -- this will display the same number twice
local a = util.CoherentNoise( 5.3 ) -- uses 5 and 6 as seeds, t equals 0.3
local b = util.CoherentNoise( 5.4 ) -- uses 5 and 6 as seeds, t equals 0.4
local c = util.CoherentNoise( 5.9 ) -- uses 5 and 6 as seeds, t equals 0.9
local d = util.CoherentNoise( 6.5 ) -- uses 6 and 7 as seeds, t equals 0.5
local e = util.CoherentNoise( 7.6 ) -- uses 7 and 8 as seeds, t equals 0.6
-- this will produce coherent noise that is seamless because the starting seed is equal
-- to the last seed used and the ending seed is equal to the next seed that will be used
print( util.CoherentNoise( CurTime() ) )
It would probably be easier to see the effects in movement or color.
I made a quick test and it looks nice
hook.Add( "CalcView", "Test", function( ply, pos, ang, fov )
local n = 0.5 - util.CoherentNoise( CurTime() * 2 )
return { angles = ang + Angle( n, n, n ) * ply:GetVelocity():Length() * 0.025 }
end )