Unity记录5.4-地图-带种子的柏林噪声

文章首发见博客:https://mwhls.top/4850.html

无图/格式错误/后续更新请见首发页。

更多更新请到mwhls.top查看

欢迎留言提问或批评建议,私信不回。
汇总:Unity 记录

现在卡在了跨地图洞穴生成,没想到什么好的方法能够像地面一样随机连续洞穴块。

摘要:带种子的柏林噪声。

FastNoise_C#-2023/9/2
  • Auburn/FastNoise_CSharp: FastNoise C# Version
  • Feature:
    • Value Noise 2D, 3D
    • Perlin Noise 2D, 3D
    • Simplex Noise 2D, 3D, 4D
    • Cubic Noise 2D, 3D
    • Gradient Perturb 2D, 3D
    • Multiple fractal options for all of the above
    • Cellular (Voronoi) Noise 2D, 3D
    • White Noise 2D, 3D, 4D
    • Supports floats or doubles
带种子的柏林噪声-2023/9/1
  • Unity的柏林噪声设置不了种子,而后续我可能会需要通过固定输入来获取地图状态,因此改用FastNoise。
实现代码-2023/08/31-2023/9/1
  • 本来还包括一个地图块的类,但是我目前的边界点和周围是相关的,和随机生成有点冲突,考虑到用空间换计算量挺划算,所以也没实现计算边界点,因此这个类没什么信息量,没放。
c 复制代码
    // Thanks to Auburn and other authers of FastNoise, I copied it in 2023/9/2 from https://github.com/Auburn/FastNoise_CSharp
    
    public class Noise{
        public int seed;
        FastNoise _noise_generator;
    
        public Noise(int seed=-1){
            if (seed == -1) seed = System.DateTime.Now.Millisecond;
            this.seed = seed;
            _noise_generator = new(seed);
        }
    
        public float perlin(int x, int y, float scale){
            _noise_generator.SetNoiseType(FastNoise.NoiseType.Perlin);
            _noise_generator.SetFrequency(1/scale);
            float noise_value = _noise_generator.GetNoise(x, y);
            return noise_value;
        }
    
        public float perlin(int x, float scale){
            _noise_generator.SetNoiseType(FastNoise.NoiseType.Perlin);
            _noise_generator.SetFrequency(1/scale);
            float noise_value = _noise_generator.GetNoise(x, 0f);
            return noise_value;
        }
    
        static float perlin(int x, int y, float scale, int seed){
            FastNoise noise_generator = new(seed);
            noise_generator.SetNoiseType(FastNoise.NoiseType.Perlin);
            noise_generator.SetFrequency(1/scale);
            float noise_value = noise_generator.GetNoise(x, y);
            return noise_value;
        }
    
        static float perlin(int x, float scale, int seed){
            float noise_value = perlin(x, 0, scale, seed);
            return noise_value;
        }
    }
相关推荐
深海潜水员6 小时前
【Behavior Tree】-- 行为树AI逻辑实现- Unity 游戏引擎实现
游戏·unity·c#
Thomas_YXQ16 小时前
Unity3D游戏内存优化指南
游戏·unity·职场和发展·性能优化·蓝桥杯·游戏引擎·unity3d
chillxiaohan16 小时前
Unity接入Steamworks.NET实现通信功能
unity
枯萎穿心攻击1 天前
响应式编程入门教程第二节:构建 ObservableProperty<T> — 封装 ReactiveProperty 的高级用法
开发语言·unity·c#·游戏引擎
X_StarX1 天前
【Unity笔记02】订阅事件-自动开门
笔记·学习·unity·游戏引擎·游戏开发·大学生
霸王•吕布2 天前
游戏引擎中顶点着色&像素着色
游戏引擎·顶点着色器·像素着色器·顶点颜色·顶点uv·顶点法向
一线灵2 天前
跨平台游戏引擎 Axmol-2.7.0 发布
c++·游戏引擎·wasm·axmol·cocos2dx
Thomas_YXQ2 天前
Unity URP法线贴图实现教程
开发语言·unity·性能优化·游戏引擎·unity3d·贴图·单一职责原则
徐子竣2 天前
[学习记录]Unity-Shader-几何着色器
unity·游戏引擎·着色器
EQ-雪梨蛋花汤2 天前
【Part 3 Unity VR眼镜端播放器开发与优化】第四节|高分辨率VR全景视频播放性能优化
unity·音视频·vr