CodeBase - Noise Library Part 1: NoiseGen.dba

Return to the CodeBase listing

Category: Libraries

Version: 1.1

0
0

Information

Uploaded: 31st Oct 2010 09:53

Modified: 5th Nov 2010 12:30

Author:  The Sab

Summary

A noise generating library written by Jason Bevins and Keith Davies for C++. Translated for use with Dark Basic Pro.

Full Description

1.1 Changes:<br /> -Minor fixes. Added some Get functions that were overlooked.<br /> <br /> NoiseGen Instructions:<br /> <br /> NoiseGen_Setup() must be called by your main program to initialize some arrays and variables<br /> <br /> Creating noise modules:<br /> <br /> variable = Create_Module(module_type)<br /> <br /> Generator Module Types with corrisponding parameters:<br /> <br /> MOD_BILLOW Clumpy, cloud-like noise<br /> parameters: frequency, lacunarity, octaveCount, persistence, noiseQuality, seed<br /> MOD_CHECKERBOARD Repeating, alternating squares<br /> parameters: none<br /> MOD_CONST Single value over entire noisemap<br /> parameters: constValue<br /> MOD_CYLINDERS Concentric cylinders. Hard to explain, and even harder to visualize without a 3d modeler<br /> parameters: frequency<br /> MOD_PERLIN The Mother of All Noise.<br /> parameters: frequency, lacunarity, octaveCount, persistence, noiseQuality, seed<br /> MOD_RIDGEDMULTI Creates mountain-like ridges<br /> parameters: frequency, lacunarity, octaveCount, noiseQuality, seed<br /> MOD_SPHERES Concentric spheres.<br /> parameters: frequency<br /> MOD_VORONOI Odd, plateau-like groupings of values<br /> parameters: frequency, seed, displacement, enableDistance<br /> <br /> Modifier Modules:<br /> <br /> MOD_ABS Gets the absolute value of the source module <br /> parameters: source0<br /> MOD_CLAMP Forces all source values between the lower and upper bounds provided<br /> parameters: source0, lowerBound, upperBound<br /> MOD_CURVE Adjusts all source values to fit along a defined curve<br /> parameters: source0, 4x ControlPoints (see detailed description below)<br /> MOD_EXPONENT Raises all source values by a provided exponent<br /> parameters: source0, exponent<br /> MOD_INVERT Makes all positive source values negative and vice versa<br /> parameters: source0<br /> MOD_SCALEBIAS Scales all source values by an amount provided, and also lowers or raises all values by a specified amount<br /> parameters: source0, scale, bias<br /> MOD_TERRACE Adjusts all source values to fit a defiend terracing curve<br /> parameters: source0, invertTerrace, 2x ControlPoints (see detailed description below)<br /> <br /> Combiner Modules:<br /> <br /> MOD_ADD Adds the values of both sources together<br /> parameters: source0, source1<br /> MOD_MAX Compares each value of both sources, and returns the highest<br /> parameters: source0, source1<br /> MOD_MIN Compares each value of both sources, and returns the lowest<br /> parameters: source0, source1<br /> MOD_MULTIPLY Multiplies the values of both sources together<br /> parameters: source0, source1<br /> MOD_POWER Raises each value of source0 by the corrisponding value of source1<br /> parameters: source0, source1<br /> <br /> Selector Modules:<br /> <br /> MOD_BLEND Mixes the two sources using the control as an alpha channel (low control values mean more of source0 shows, higher control values means more of source1 shows)<br /> parameters: source0, source1, control<br /> MOD_SELECT Selects one source or the other depending on the control value range (any control value within the specified range will use source1 values, otherwise source0 values will be used)<br /> parameters: source0, source1, control, lowerbound, upperbound, falloff<br /> <br /> Transformer Modules:<br /> <br /> MOD_DISPLACE Shifts all values from source0. The x-axis is shifted by source1, y-axis by source2, z-axis by source3<br /> parameters: source0, source1, source2, source3<br /> MOD_ROTATEPOINT Rotates the entire source along the provided angles.<br /> parameters: source0, XYZAngles (see detailed description below)<br /> MOD_SCALEPOINT Stretches or compresses source values along provided x, y, and z amounts<br /> parameters: source0, XYZScale (see detailed description below)<br /> MOD_TRANSLATEPOINT Shifts all values from source0 by the specified x, y, z amounts<br /> parameters: source0, XYZTranslation (see detailed description below)<br /> MOD_TURBULANCE Swirls up all the values from source0 using an internal perlin noise function for each axis<br /> parameters: source0, power, roughness, frequency, seed<br /> <br /> Parameters and how to set them:<br /> <br /> source0 Set_Source0(main_module, source_module)<br /> source1 Set_Source1(main_module, source_module)<br /> source2 Set_Source2(main_module, source_module)<br /> source3 Set_Source3(main_module, source_module)<br /> control Set_Control(main_module, control_module)<br /> All sources and controls default to -1, which will produce an error, so if a module requires a source, you must set it.<br /> <br /> frequency Set_Frequency(main_module, float value) Default 1.0<br /> Frequency is how often a wave completes a cycle in a give interval: higher frequency equals more but smaller artifacts<br /> <br /> lacunarity Set_Lacunarity(main_module, float value) Default 2.0<br /> Lacunarity is how much the frequency changes between octaves: 2.0 means the frequency doubles every octave.<br /> <br /> octaveCount Set_OctaveCount(main_module, integer value) Default 6<br /> Number of octaves to run the noise formula through: more octaves = more detail, but longer processing<br /> <br /> persistence Set_Persistence(main_module, float value) Default 0.5<br /> Persistence is how much the amplitude changes between octaves: 0.5 means the amplitude is halved each octave<br /> <br /> noiseQuality Set_NoiseQuality(main_module, quality value) Default QUALITY_STD<br /> NoiseQuality comes in three flavors: QUALITY_FAST, QUALITY_STD, and QUALITY_BEST, which use linear, quadratic, and quintic interpolation respectively. Better equals slower.<br /> <br /> seed Set_Seed(main_module, integer value) Default 0<br /> If the seed stays the same, then the pattern produced will also be the same every time the program is run. Controlable pseudo-random noise at its best.<br /> <br /> amplitude - This is not an adjustable parameter, as all noise modules create values between -1.0 and 1.0<br /> *NOTE* Due to the way Perlin Noise works, if you have more than one octave, you will probably get some values beyond the -1.0..1.0 range. If this is undesirable, <br /> than a Clamp or ScaleBias module should be used to adjust it<br /> <br /> constValue Set_ConstValue(main_module, float value) Default 0.0<br /> MOD_CONST only. This is the value that will fill the whole noise map<br /> <br /> displacement Set_Displacement(main_module, float value) Default 1.0<br /> enableDistance Set_EnableDistance(main_module, boolean) Default falso<br /> MOD_VORONOI only. Displacement is a multiplier applied to the formula. Setting enableDistance to True causes circular patterns to appear in the mix. I don't know if that is the <br /> intentional outcome, or if I just screwed up the formula.<br /> <br /> lowerBound Set_LowerBound(main_module, float value) Default -1.0<br /> upperBound Set_UpperBound(main_module, float value) Default 1.0<br /> These are the bounds by which MOD_CLAMP restrains its values and MOD_SELECT determines which source module gets drawn where.<br /> <br /> exponent Set_Exponent(main_module, float value) Default 1.0<br /> MOD_EXPONENT only. The value that the source is raised to.<br /> <br /> scale Set_Scale(main_module, float value) Default 1.0<br /> bias Set_Bias(main_module, float value) Default 0.0<br /> MOD_SCALEBIAS only. Scale resizes the entire source module; 0.5 would halve all values in the source, while bias raises or lowers it.<br /> <br /> edgeFallOff Set_EdgeFallOff(main_module, float value) Default 0.0<br /> MOD_SELECT only. This value smooths the transition between the borders of the two sources.<br /> <br /> power Set_Power(main_module, float value) Default 1.0<br /> roughness *Not set-up yet* Technical issues Default 3<br /> MOD_TURBULENCE only. Power is simply how strong the turbulence is. Roughness is the octaveCount for the 3 built in Perlin functions, which is why I haven't come up with a <br /> good way to set them without causing a crash.<br /> <br /> xAngle Set_AnglesXYZ(main_module, float value x, float value y, float value z) Default 0.0 on all of them<br /> yAngle These are the angles that the source image will be rotated around. Angles are in degrees. *<br /> zAngle I am thinking about combining all of these with Scale and Translate, so as just to have an X, Y, Z. I was worried it would be too confusing though, so left it for the time being<br /> <br /> xScale Set_ScaleXYZ(main_module, float value x, float value y, float value z) Default 1.0 on all of them<br /> yScale These are what the source module will be scaled by.<br /> zScale<br /> <br /> xTranslation Set_TranslationXYZ(main_module, float value x, float value y, float value z) Default 0.0 on all of them<br /> yTranslation These are what the source module will be shifted by<br /> zTranslation<br /> <br /> * For those who are familiar with C++ also, and are digging through the code, keep in mind that C++ calculates in radians by default, while DBPro uses degrees by default.<br /> <br /> controlPoints Both MOD_CURVE and MOD_TERRACE require an array of control points to work. The controlPoints are similiar, and I used a master array to support them both<br /> I have also put a hard cap of 255 control points for each module(which is obscenely high, so don't complain) and a total number of Curve and Terrace modules<br /> also at 255. C++ has the ability to make instanced arrays. DBPro does not, so this is the only workable solution I could come up with.<br /> Curve_ClearAllControlPoints(main_module) Empties the array for the given MOD_CURVE<br /> Curve_AddControlPoint(main_module, input float, output float) Adds a control point. Can be added in any order, the program will sort them. Minimum of 4 required for Curves<br /> <br /> Terrace_ClearAllControlPoints(main_module) Empties the array for the given MOD_TERRACE<br /> Terrace_AddControlPoint(main_module, value float) Adds a control point. Can be added in any order, the program will sort them. Minimum of 2 required for Terraces<br /> <br /> invertTerraces Set_InvertTerraces(main_module, boolean) Default False<br /> MOD_TERRACE only. Inverts the terraces.<br /> <br /> For MOD_CURVE: When a value is passed to a Curve Module, that value is interpolated between the control points in the array. It can be used to create sharper peaks at extreme values, but more<br /> level values around zero. Hard to explain. Wish I could supply a chart<br /> <br /> for MOD_TERRACE: When a value is passed to a Terrace Module, that value will be interpolated between the control points in the array. Values close to the control points won't be changed much, but<br /> the values furtherest between control points will favor the lower control point. Unless invertTerraces is set to True. Again, I wish I could supply a chart.

Comments

No comments yet.