Added test for noise compositing

This commit is contained in:
Michaël Lemaire 2016-01-06 00:47:45 +01:00
parent 17fbaf5fce
commit 252d7e7b87
6 changed files with 21 additions and 7 deletions

View file

@ -110,7 +110,7 @@ double FractalNoise::get3d(double detail, double x, double y, double z) const {
decltype(state_level_count) i = 0; decltype(state_level_count) i = 0;
while (current_height >= detail) { while (current_height >= detail) {
const NoiseState::NoiseOffset &offset = state.level_offsets[i]; auto offset = state.level_offsets[i];
result += result +=
getBase3d(offset.x + x * current_scaling, offset.y + y * current_scaling, offset.z + z * current_scaling) * getBase3d(offset.x + x * current_scaling, offset.y + y * current_scaling, offset.z + z * current_scaling) *

View file

@ -15,7 +15,7 @@ void NoiseNode::randomize(RandomGenerator &random) {
noise->randomize(random); noise->randomize(random);
} }
void NoiseNode::setConfig(double scaling, double step_scaling, double height, double step_height) { void NoiseNode::setConfig(double scaling, double height, double step_scaling, double step_height) {
noise->setScaling(scaling, height); noise->setScaling(scaling, height);
noise->setStep(step_scaling, step_height); noise->setStep(step_scaling, step_height);
} }

View file

@ -28,7 +28,7 @@ class DEFINITIONSHARED_EXPORT NoiseNode : public DefinitionNode {
/** /**
* Set the noise configuration. * Set the noise configuration.
*/ */
void setConfig(double scaling, double step_scaling = 0.5, double height = 1.0, double step_height = 0.5); void setConfig(double scaling, double height = 1.0, double step_scaling = 0.5, double step_height = 1.0);
protected: protected:
virtual void save(PackStream *stream) const override; virtual void save(PackStream *stream) const override;

View file

@ -49,8 +49,6 @@ void TexturesDefinition::applyPreset(TexturesPreset preset, RandomGenerator &ran
layer.applyPreset(TextureLayerDefinition::TEXTURES_LAYER_PRESET_SNOW, random); layer.applyPreset(TextureLayerDefinition::TEXTURES_LAYER_PRESET_SNOW, random);
layer.setName("Snow"); layer.setName("Snow");
addLayer(layer); addLayer(layer);
} else if (preset == TEXTURES_PRESET_CANYON) {
/* TODO */
} }
} }

View file

@ -19,8 +19,7 @@ class DEFINITIONSHARED_EXPORT TexturesDefinition : public Layers {
typedef enum { typedef enum {
TEXTURES_PRESET_FULL, TEXTURES_PRESET_FULL,
TEXTURES_PRESET_IRELAND, TEXTURES_PRESET_IRELAND,
TEXTURES_PRESET_ALPS, TEXTURES_PRESET_ALPS
TEXTURES_PRESET_CANYON
} TexturesPreset; } TexturesPreset;
void applyPreset(TexturesPreset preset, RandomGenerator &random = RandomGeneratorDefault); void applyPreset(TexturesPreset preset, RandomGenerator &random = RandomGeneratorDefault);

View file

@ -32,6 +32,7 @@
#include "RandomGenerator.h" #include "RandomGenerator.h"
#include "NoiseFunctionSimplex.h" #include "NoiseFunctionSimplex.h"
#include <cmath>
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
@ -66,6 +67,22 @@ static void testNoise() {
filename = getFileName("noise_simplex_cache_normal"); filename = getFileName("noise_simplex_cache_normal");
cout << "Rendering " << filename << "..." << endl; cout << "Rendering " << filename << "..." << endl;
noise.getNormalTexture()->saveToFile(filename); noise.getNormalTexture()->saveToFile(filename);
const int size = 1024;
const double scale = 0.01;
Texture2D pic(size, size);
for (int i = 0; i < 10; i++) {
filename = getFileName("noise_simplex_compo", i);
cout << "Rendering " << filename << "..." << endl;
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
double val =
noise.get2d(pow(0.5, to_double(i)), to_double(x) * scale, to_double(y) * scale) * 0.5 + 0.5;
pic.setPixel(x, y, Color(val, val, val));
}
}
pic.saveToFile(filename);
}
} }
static void testGroundShadowQuality() { static void testGroundShadowQuality() {