Archived

This topic is now archived and is closed to further replies.

2D Perlin noise in one function

This topic is 5405 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I have read a dozens of articles about perlin noise and i can get some fine results in 1D. When it comes to 2D i can''t follow it anymore. (I looked at http://freespace.virgin.net/hugo.elias/models/m_perlin.htm) I made lot''s of different approaches for a decent function that could do it ) I was wondering of anyone simplified it into one function that i could look at to compare?

Share on other sites
The good news is, I simplified it into a couple functions...
The bad news is, it''s a curryfied O''Caml function...

I''ll post it here anyways:

(*-------*)			let add_noise buffer amplitude = 					let w = width buffer			and h = height buffer in							for i = 0 to w - 1 do									for j = 0 to h - 1 do											buffer.(i).(j) <- buffer.(i).(j) +. amplitude *. ( 1. -. ( Random.float 2.) );										done;				done;					buffer(*-------*)		let rec generate filter x y amplitude falloff =					if ( x <= 1 ) && ( y <= 1 ) then							add_noise ( create 1 1 0. ) (amplitude *. falloff)							else							add_noise ( 					resize filter ( 						generate filter ((x+1)/2) ((y+1)/2) (amplitude *.falloff) falloff ) x y ) 					(amplitude *.falloff)(*-------*)	let resize filter buffer w h =			let result = Array.make_matrix w h ( buffer.(0).(0) ) in					for i = 0 to w - 1 do							for j = 0 to h - 1 do									let x = float_of_int(i) /. float_of_int ( w - 1 )					and y = float_of_int(j) /. float_of_int ( h - 1 ) in												result.(i).(j) <- filter buffer x y;								done;							done;						result

Then, call "generate" with, as arguments, your filter (linear, nearest-point, or whatever) function, the width and height, the amplitude, and amplitude reduction.

ToohrVyk

Share on other sites
Yay! another OCamler

Nothing useful to add, just makes me feel good hehe.

• 39
• 12
• 10
• 10
• 9
• Forum Statistics

• Total Topics
631365
• Total Posts
2999590
×