public override double GetWrapped(double x, double y, int wrap) { double value = 0.0; double signal = 0.0; double curPersistence = 1.0; long seed; double lacunarity = Lacunarity.GetWrapped(x, y, wrap); double persist = Persistence.GetWrapped(x, y, wrap); double frequency = Frequency.GetWrapped(x, y, wrap); x *= frequency; y *= frequency; int mOctaveCount = (int)OctaveCount.GetWrapped(x, y, wrap); for (int currentOctave = 0; currentOctave < mOctaveCount; currentOctave++) { seed = (Seed + currentOctave) & 0xffffffff; signal = GradientCoherentNoiseWrap(x, y, wrap, (int)seed, NoiseQuality); value += signal * curPersistence; x *= lacunarity; y *= lacunarity; curPersistence *= persist; } return(value); }
public override double GetValue(double x, double y, double z) { double value = 0.0; double signal = 0.0; double curPersistence = 1.0; long seed; double lacunarity = Lacunarity.GetValue(x, y, z); double persist = Persistence.GetValue(x, y, z); double frequency = Frequency.GetValue(x, y, z); x *= frequency; y *= frequency; z *= frequency; int mOctaveCount = (int)OctaveCount.GetValue(x, y, z); for (int currentOctave = 0; currentOctave < mOctaveCount; currentOctave++) { seed = (Seed + currentOctave) & 0xffffffff; signal = GradientCoherentNoise(x, y, z, (int)seed, NoiseQuality); signal = 2.0 * System.Math.Abs(signal) - 1.0; value += signal * curPersistence; x *= lacunarity; y *= lacunarity; z *= lacunarity; curPersistence *= persist; } value += 0.5; return(value); }
public override double GetValue(double x, double y, double z) { double lacunarity = Lacunarity.GetValue(x, y, z); double frequency = Frequency.GetValue(x, y, z); x *= frequency; y *= frequency; z *= frequency; int mOctaveCount = (int)OctaveCount.GetValue(x, y, z); double signal = 0.0; double value = 0.0; double weight = 1.0; // These parameters should be user-defined; they may be exposed in a // future version of libnoise. double offset = 1.0; double gain = 2.0; for (int currentOctave = 0; currentOctave < mOctaveCount; currentOctave++) { long seed = (Seed + currentOctave) & 0x7fffffff; signal = GradientCoherentNoise(x, y, z, (int)seed, NoiseQuality); // Make the ridges. signal = System.Math.Abs(signal); signal = offset - signal; // Square the signal to increase the sharpness of the ridges. signal *= signal; // The weighting from the previous octave is applied to the signal. // Larger values have higher weights, producing sharp points along the // ridges. signal *= weight; // Weight successive contributions by the previous signal. weight = signal * gain; if (weight > 1.0) { weight = 1.0; } if (weight < 0.0) { weight = 0.0; } // Add the signal to the output value. value += (signal * SpectralWeights[currentOctave]); // Go to the next octave. x *= lacunarity; y *= lacunarity; z *= lacunarity; } return((value * 1.25) - 1.0); }
protected override void EnableProperties() { Octaves.IsVisibleWhen(FractalType, f => f.CurrentValue != PropertiesFractalType.None); Lacunarity.IsVisibleWhen(FractalType, f => f.CurrentValue != PropertiesFractalType.None); Gain.IsVisibleWhen(FractalType, f => f.CurrentValue != PropertiesFractalType.None); WeightedStrength.IsVisibleWhen(FractalType, f => f.CurrentValue != PropertiesFractalType.None); PingPongStrength.IsVisibleWhen(FractalType, f => f.CurrentValue == PropertiesFractalType.PingPong); }
public override double GetWrapped(double x, double y, int wrap) { double lacunarity = Lacunarity.GetWrapped(x, y, wrap); double gain = Gain.GetWrapped(x, y, wrap); double offset = Offset.GetWrapped(x, y, wrap); double frequency = Frequency.GetWrapped(x, y, wrap); x *= frequency; y *= frequency; int mOctaveCount = (int)OctaveCount.GetWrapped(x, y, wrap); double signal = 0.0; double value = 0.0; double weight = 1.0; for (int currentOctave = 0; currentOctave < mOctaveCount; currentOctave++) { long seed = (Seed + currentOctave) & 0x7fffffff; signal = GradientNoise.GradientCoherentNoiseWrap(x, y, wrap, (int)seed, NoiseQuality); // Make the ridges. signal = System.Math.Abs(signal); signal = offset - signal; // Square the signal to increase the sharpness of the ridges. signal *= signal; // The weighting from the previous octave is applied to the signal. // Larger values have higher weights, producing sharp points along the // ridges. signal *= weight; // Weight successive contributions by the previous signal. weight = signal * gain; if (weight > 1.0) { weight = 1.0; } else if (weight < 0.0) { weight = 0.0; } // Add the signal to the output value. value += (signal * SpectralWeights[currentOctave]); // Go to the next octave. x *= lacunarity; y *= lacunarity; } return((value * 1.25) - 1.0); }
private void CalculateSpectralWeights() { double h = 1.0; double lacunarity = Lacunarity.GetValue(0, 0); double frequency = 1.0; for (int i = 0; i < MaxOctaves; i++) { // Compute weight for each frequency. SpectralWeights[i] = System.Math.Pow(frequency, -h); frequency *= lacunarity; } }
public override DrawStackNode Allocate(DrawInfo info, SurfaceTexture tex, ref int stackID) { // Stack required. // Allocate a target stack now: int targetStack = stackID; DrawStack stack = tex.GetStack(targetStack, info); stackID++; float curAmplitude = 1f; float curFrequency = (float)Frequency.GetValue(0, 0); float lacunarity = (float)Lacunarity.GetValue(0, 0); float persistence = (float)Persistence.GetValue(0, 0); int mOctaveCount = (int)OctaveCount.GetValue(0, 0); Material[] materials = new Material[mOctaveCount]; // Stack up "OctaveCount" quads. for (int currentOctave = 0; currentOctave < mOctaveCount; currentOctave++) { // Update seed: long seed = (Seed + currentOctave) & 0xffffffff; // And a material. UnityEngine.Material material = GetMaterial(TypeID, SubMaterialID); // _Data (Seed, Frequency, Amplitude, Jitter): material.SetVector("_Data", new Vector4(seed, curFrequency, curAmplitude, 0f)); // Add to set: materials[currentOctave] = material; curFrequency *= lacunarity; curAmplitude *= persistence; } // Create our node: BlockStackNode bsn = new BlockStackNode(); DrawStore = bsn; bsn.Mesh = info.Mesh; bsn.Materials = materials; bsn.Stack = stack; return(bsn); }
public override double GetWrapped(double x, double y, int wrap) { double value = 0.0; double signal = 0.0; double curPersistence = 1.0; //double nx, ny, nz; long seed; double lacunarity = Lacunarity.GetWrapped(x, y, wrap); double persist = Persistence.GetWrapped(x, y, wrap); double frequency = Frequency.GetWrapped(x, y, wrap); x *= frequency; y *= frequency; int mOctaveCount = (int)OctaveCount.GetWrapped(x, y, wrap); for (int currentOctave = 0; currentOctave < mOctaveCount; currentOctave++) { /*nx = Math.MakeInt32Range(x); * ny = Math.MakeInt32Range(y); * nz = Math.MakeInt32Range(z);*/ seed = (Seed + currentOctave) & 0xffffffff; signal = GradientNoise.GradientCoherentNoiseWrap(x, y, wrap, (int)seed, NoiseQuality); signal = 2.0 * System.Math.Abs(signal) - 1.0; value += signal * curPersistence; x *= lacunarity; y *= lacunarity; curPersistence *= persist; } value += 0.5; return(value); }
public void Hydrate() { if (IsHydrated == false) { name = "NEW Terrain Layer [Reference]"; Octaves = ScriptableObject.CreateInstance <Int_MinMax_Reference>(); Octaves.Hydrate(); Octaves.name = "Octaves"; Octaves.IsHydrated = true; Scale = ScriptableObject.CreateInstance <Float_MinMax_Reference>(); Scale.Hydrate(); Scale.name = "Scale"; Scale.IsHydrated = true; Persistance = ScriptableObject.CreateInstance <Float_MinMax_Reference>(); Persistance.Hydrate(); Persistance.name = "Persistance"; Persistance.IsHydrated = true; Lacunarity = ScriptableObject.CreateInstance <Float_MinMax_Reference>(); Lacunarity.Hydrate(); Lacunarity.name = "Lacunarity"; Lacunarity.IsHydrated = true; Root = ScriptableObject.CreateInstance <Float_MinMax_Reference>(); Root.Hydrate(); Root.name = "Root"; Root.IsHydrated = true; Magnitude = ScriptableObject.CreateInstance <Float_MinMax_Reference>(); Magnitude.Hydrate(); Magnitude.name = "Magnitude"; Magnitude.IsHydrated = true; } }