Something went wrong. Try again.
Simple scenery generator
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859#include "heightnoise_genlayer.h"
#include <godot_cpp/classes/fast_noise_lite.hpp>
#include "chunk.h"#include "utils/bmutils.h"
using namespace godot;
HeightnoiseGenlayer::HeightnoiseGenlayer(BMWorld * world) : GenerationLayer2D(world){ noiseGenerator = memnew(FastNoiseLite); noiseGeneratorMountains = memnew(FastNoiseLite);
noiseGenerator->set_noise_type(FastNoiseLite::NoiseType::TYPE_PERLIN); noiseGenerator->set_frequency(1.0f); noiseGenerator->set_fractal_lacunarity(2.0f); noiseGenerator->set_fractal_gain(0.5f); noiseGenerator->set_fractal_type(FastNoiseLite::FRACTAL_FBM);
noiseGeneratorMountains->set_noise_type(FastNoiseLite::NoiseType::TYPE_PERLIN); noiseGeneratorMountains->set_frequency(0.1f); noiseGeneratorMountains->set_fractal_lacunarity(2.0f); noiseGeneratorMountains->set_fractal_gain(0.5f); noiseGeneratorMountains->set_fractal_type(FastNoiseLite::FRACTAL_FBM);
// noiseGenerator->set_noise_type(FastNoiseLite::NoiseType::TYPE_PERLIN); // noiseGenerator->set_frequency(0.015625); // noiseGenerator->set_fractal_lacunarity(2.0f); // noiseGenerator->set_fractal_gain(0.5f); // noiseGenerator->set_fractal_type(FastNoiseLite::FRACTAL_FBM);
// noiseGeneratorMountains->set_noise_type(FastNoiseLite::NoiseType::TYPE_PERLIN); // noiseGeneratorMountains->set_frequency(0.0015625f); // noiseGeneratorMountains->set_fractal_lacunarity(2.0f); // noiseGeneratorMountains->set_fractal_gain(0.5f); // noiseGeneratorMountains->set_fractal_type(FastNoiseLite::FRACTAL_FBM);}
void HeightnoiseGenlayer::UpdateEditorParametersCallback(){ noiseGenerator->set_seed(world->GetRandSeed()); noiseGeneratorMountains->set_seed(world->GetRandSeed()); chunkRes = world->GetChunkRes();};
float_t HeightnoiseGenlayer::GetValue(Vector2 pos){ UpdateEditorParameters(); float_t mountain = (noiseGeneratorMountains->get_noise_2d(pos.x/(float_t)chunkRes,pos.y/(float_t)chunkRes) + 1) / 2; float_t noise = (noiseGenerator->get_noise_2d(pos.x,pos.y) + 1) / 2; float_t v = mountain * mountain * mountain * mountain + noise * 0.01; return v;}
float_t HeightnoiseGenlayer::Normalized2Real(float_t normalized){ return normalized*heightRange + heightOffset;}
float_t HeightnoiseGenlayer::Real2Normalized(float_t real){ return (real - heightOffset) / heightRange;}