public static NoiseSetting Lerp(NoiseSetting n1, NoiseSetting n2, float t) { n1.Intensity = Mathf.Lerp(n1.Intensity, n2.Intensity, t); n1.Speed = Mathf.Lerp(n1.Speed, n2.Speed, t); n1.Scale = Mathf.Lerp(n1.Scale, n2.Scale, t); return(n1); }
private Vector3 AddNoise(Vector3 point, NoiseSetting setting, float time, int offset) { point.x += (float)noise.Evaluate((offset * 0.92347) + point.x * setting.Scale, time * setting.Speed) * setting.Intensity; point.y += (float)noise.Evaluate((offset * 0.23474) + point.y * setting.Scale, time * setting.Speed) * setting.Intensity; point.z += (float)noise.Evaluate((offset * 0.34786) + point.z * setting.Scale, time * setting.Speed) * setting.Intensity; return(point); }
public NoiseSetting(NoiseSetting ns, Vector3 exta_offset) { scale_x = ns.scale_x; scale_y = ns.scale_y; scale_z = ns.scale_z; offset = ns.offset + exta_offset; }
public NoiseGen2(NoiseSetting ns) { Debug.Log("noise gen 2 constructor"); noise_set = ns; fn = new FastNoise(); fn.SetNoiseType(FastNoise.NoiseType.PerlinFractal); fn.SetFractalOctaves(3); fn.SetFractalLacunarity(2f); fn.SetFractalGain(0.5f); fn.SetFrequency(1f); }
public static float Evaluate(Vector3 point, NoiseSetting setting) { float noiseValue = 0f; float freq = setting.BaseRoughness; float amp = 1f; for (int i = 0; i < setting.Octave; ++i) { float v = _Evaluate(point * freq + setting.Center); noiseValue += (v + 1) * 0.5f * amp; freq *= setting.Roughness; amp *= setting.Persistence; } noiseValue = noiseValue - setting.Threshold; return(noiseValue * setting.Strength); }
public static float Evaluate(Vector3 point, NoiseSetting setting) { float noiseValue = 0f; float freq = setting.BaseRoughness; float amp = 1f; float weight = 1f; for (int i = 0; i < setting.Octave; ++i) { float v = 1f - Mathf.Abs(_Evaluate(point * freq + setting.Center)); v *= v; v *= weight; weight = Mathf.Clamp01(v * setting.WeightMultiper); noiseValue += v * amp; freq *= setting.Roughness; amp *= setting.Persistence; } noiseValue = noiseValue - setting.Threshold; return(noiseValue * setting.Strength); }
public static float Evaluate(Vector3 point, NoiseSetting setting) { if (WardBenjaminNoise.Seed == 0) { WardBenjaminNoise.Seed = 114514; } float noiseValue = 0f; float freq = setting.BaseRoughness; float amp = 1f; for (int i = 0; i < setting.Octave; ++i) { float v = _Evaluate(point * freq + setting.Center); noiseValue += (v + 1) * 0.5f * amp; freq *= setting.Roughness; amp *= setting.Persistence; } noiseValue = Mathf.Max(0f, noiseValue - setting.Threshold); return(noiseValue * setting.Strength); }
public static float GenerateTerrainNoise(Vector3 point, NoiseSetting setting) { float maxPossibleHeight = 0; float amplitude = 1; float frequency = 1; float returnNoise = 0; for (int i = 0; i < setting.octaves; i++) { maxPossibleHeight += amplitude; amplitude *= setting.persistance; } if (setting.noiseScale <= 0) { setting.noiseScale = 0.0001f; } amplitude = 1; for (int i = 0; i < setting.octaves; i++) { Vector3 sample = (point / setting.noiseScale) * frequency; float perlinValue = Perlin3D(sample); returnNoise += perlinValue * amplitude; amplitude *= setting.persistance; frequency *= setting.lacunarity; } return(returnNoise / maxPossibleHeight); }
public static List <MarchingCube> InitVertices(Vector3 center, MarchingCubeChunkSetting marchingCubeChunksettings, NoiseSetting noiseSetting) { List <MarchingCube> cubeList = new List <MarchingCube>(); for (int x = 0; x < marchingCubeChunksettings.numberOfVerticesPerLine; x++) { for (int y = 0; y < marchingCubeChunksettings.numberOfVerticesPerLine; y++) { for (int z = 0; z < marchingCubeChunksettings.numberOfVerticesPerLine; z++) { MarchingCube cube = new MarchingCube(new Vector3(x, y, z) * marchingCubeChunksettings.distanceBetweenVertex + center, marchingCubeChunksettings.distanceBetweenVertex); cubeList.Add(cube); for (int i = 0; i < 8; i++) { CalculateVertexWeight(cube, i, marchingCubeChunksettings, noiseSetting); } } } } return(cubeList); }
public void Initialize(NoiseSetting _setting) { mSetting = _setting; }
void ThreadMeshData(MeshData meshData, Vector3 center, MarchingCubeChunkSetting chunkSetting, NoiseSetting noiseSetting, Action <MeshData> callback) { List <MarchingCube> cubes = MarchingCubeChunk.InitVertices(center, chunkSetting, noiseSetting); Vector3[] vertices = MarchingCubeChunk.GenerateVertices(cubes); meshData.cubes = cubes; meshData.vertices = vertices; meshData.triangles = MarchingCubeChunk.GenerateTriangles(vertices); meshData.uvs = biomeSetting.GenerateUVS(this.chunkSetting, vertices); lock (meshDataThreadInfoQueue) { meshDataThreadInfoQueue.Enqueue(new GeneratorThreadInfo <MeshData>(callback, meshData)); } }
public void RequestMeshData(MeshData meshData, Vector3 center, MarchingCubeChunkSetting chunkSettings, NoiseSetting noiseSettings, Action <MeshData> callback) { ThreadStart threadStart = delegate { ThreadMeshData(meshData, center, chunkSettings, noiseSettings, callback); }; new Thread(threadStart).Start(); }
public BlockyGen1(NoiseSetting ns, GeomNoiseSettings gns, BlockyV1Settings bs) { noise_set = ns; geom_nois_set = gns; blocky_set = bs; }
static void CalculateVertexWeight(MarchingCube cube, int index, MarchingCubeChunkSetting marchingCubeSetting, NoiseSetting noiseSetting) { //Cube neigborCube; //check there is exsiting noise value at neighbor //Skip this process because we use perlin noise //if(cubeDictionary.TryGetValue(new Vector3(vertexPosition.x - someOffset?, vertexPosition.y, vertexPosition.z), out neigborCube) { // ... //} else if ... //For threading, we have to dupulicate Animation Curve AnimationCurve weightCurve = new AnimationCurve(marchingCubeSetting.weightCurve.keys); float height = cube.origin.y + cube.offset[index].y; float height01 = Mathf.Lerp(1, 0, (marchingCubeSetting.mapMaxHeight - height) / (marchingCubeSetting.mapMaxHeight - marchingCubeSetting.mapMinHeight)); float weight = MarchingCubeNoise.GenerateTerrainNoise(cube.origin + cube.offset[index], noiseSetting) * weightCurve.Evaluate(height01); if (height < marchingCubeSetting.mapMinHeight + cube.offsetDistance) { weight = 1; } else if (height > marchingCubeSetting.mapMaxHeight - cube.offsetDistance) { weight = 0; } cube.vertexSelected[index] = weight < marchingCubeSetting.ignoreVertexLevel; cube.vertexWeight[index] = weight; }
private float AddNoise(float value, NoiseSetting setting, float time, int offset) { value += (float)noise.Evaluate(value * setting.Scale, time + offset * setting.Speed) * setting.Intensity; return(value); }
private async Task UpdateWisps(float time, float deltaTime) { await new WaitForBackgroundThread(); for (int i = 0; i < forces.Length; i++) { Force force = forces[i]; force.IsIntersecting = false; forces[i] = force; } // Update wisp forces totalHeatTarget = 0; for (int i = 0; i < numWisps; i++) { Wisp w1 = wisps[i]; for (int forceIndex = 0; forceIndex < forces.Length; forceIndex++) { Force force = forces[forceIndex]; float touchingDist = force.Radius + w1.Radius; float prevPointDistSqr = (w1.Point - force.PrevPoint).sqrMagnitude; float pointDistSqr = (w1.Point - force.Point).sqrMagnitude; if (pointDistSqr < (touchingDist * touchingDist) || prevPointDistSqr < (touchingDist * touchingDist)) { force.IsIntersecting = true; w1.Heat = Mathf.Clamp01(w1.Heat + (deltaTime * heatGainSpeed)); w1.Velocity -= (force.Velocity * w1.Heat); forces[forceIndex] = force; } } w1.Radius = AddNoise(w1.TargetRadius, ambientNoise, time, i); Vector3 point = w1.Point; point += (w1.Velocity * deltaTime); w1.Velocity = Vector3.Lerp(w1.Velocity, w1.Velocity * velocityDampen, deltaTime); point = Vector3.Lerp(point, w1.TargetPoint, seekStrength * deltaTime); point = AddNoise(point, NoiseSetting.Lerp(ambientNoise, agitatedNoise, w1.Heat), time, i); w1.Point = point; w1.Heat = Mathf.Clamp01(w1.Heat - (deltaTime * heatDissipateSpeed)); totalHeatTarget += w1.Heat; wisps[i] = w1; } await Task.Yield(); // Generate quads for (int i = 0; i < numWisps; i++) { Wisp wisp = wisps[i]; Quad quad = quads[i]; RenderOrder r = renderOrder[i]; wisp.Depth = (wisp.Point - cameraPos).sqrMagnitude; Color color = baseWispColor.Evaluate(Mathf.Repeat((time + (i * offsetMultiplier)) * colorCycleSpeed, 1f)); color += heatWispColor.Evaluate(wisp.Heat); color = Color.Lerp(color, transitionColor, transitionColor.a); wisps[i] = wisp; int tileNum = wisp.TileOffset + currentTileNum; if (tileNum >= numTiles) { tileNum -= numTiles; } quad = Quad.FromWisp(color, wisp.Point, wisp.Radius + (wisp.Heat * heatRadiusMultiplier), cameraUp, cameraRht, tileOffsets[tileNum], tileScale); quads[i] = quad; r.Index = i; r.Depth = wisp.Depth; renderOrder[i] = r; } renderOrder.Sort(delegate(RenderOrder r1, RenderOrder r2) { return(r2.Depth.CompareTo(r1.Depth)); }); }
public OpenSimplexNoise(NoiseSetting setting) { Setting = setting; }
public NoiseGen1Geom(NoiseSetting ns, GeomNoiseSettings gns) { noise_set = ns; geom_nois_set = gns; }
public PerlinNoise(NoiseSetting setting) { Setting = setting; }
public NoiseGen1Geom(NoiseSetting ns) { noise_set = ns; }
public BlockyGen1(NoiseSetting ns) { noise_set = ns; }