Fixed noise scaling in opengl

This commit is contained in:
Michaël Lemaire 2016-01-04 20:26:40 +01:00
parent c81d86d187
commit 02a026116d
3 changed files with 45 additions and 20 deletions

View file

@ -476,18 +476,22 @@ double NoiseFunctionSimplex::getBase3d(double x, double y, double z) const {
return noiseSimplexGet3DValue(x, y, z) - 0.5;
}
static constexpr double TEXTURE_SCALING = 15.0;
static Texture2D *_valueTexture = NULL;
const Texture2D *NoiseFunctionSimplex::getValueTexture() {
if (!_valueTexture) {
const int width = 1024;
const int height = 1024;
const int width = 2048;
const int height = 2048;
_valueTexture = new Texture2D(width, height);
for (int x = 0; x < width; x++) {
for (int z = 0; z < height; z++) {
double val = noiseSimplexGet2DValue(to_double(x), to_double(z)) - 0.5;
// TODO Make texture tileable
double dx = to_double(x) / to_double(width);
double dz = to_double(z) / to_double(height);
double val = noiseSimplexGet2DValue(TEXTURE_SCALING * dx, TEXTURE_SCALING * dz);
_valueTexture->setPixel(x, z, Color(val, val, val));
}
}
@ -500,22 +504,27 @@ static Texture2D *_normalTexture = NULL;
const Texture2D *NoiseFunctionSimplex::getNormalTexture() {
if (!_normalTexture) {
const int width = 1024;
const int height = 1024;
const int width = 2048;
const int height = 2048;
_normalTexture = new Texture2D(width, height);
double scale = TEXTURE_SCALING;
double offset = scale * 0.1;
for (int x = 0; x < width; x++) {
for (int z = 0; z < height; z++) {
// TODO Make texture tileable
double vcenter = noiseSimplexGet2DValue(0.01 * to_double(x), 0.01 * to_double(z)) - 0.5;
double vsouth = noiseSimplexGet2DValue(0.01 * to_double(x), 0.01 * to_double(z) + 0.001) - 0.5;
double veast = noiseSimplexGet2DValue(0.01 * to_double(x) + 0.001, 0.01 * to_double(z)) - 0.5;
double dx = to_double(x) / to_double(width);
double dz = to_double(z) / to_double(height);
double vcenter = noiseSimplexGet2DValue(scale * dx, scale * dz) - 0.5;
double vsouth = noiseSimplexGet2DValue(scale * dx, scale * dz + offset) - 0.5;
double veast = noiseSimplexGet2DValue(scale * dx + offset, scale * dz) - 0.5;
Vector3 normal = Geometry::getNormalFromTriangle(Vector3(0.0, vcenter, 0.0), Vector3(0.0, vsouth, 0.01),
Vector3(0.01, veast, 0.0));
Vector3 normal = Geometry::getNormalFromTriangle(
Vector3(0.0, vcenter, 0.0), Vector3(0.0, vsouth, offset), Vector3(offset, veast, 0.0));
_normalTexture->setPixel(x, z, Color(normal.x, normal.y, normal.z));
_normalTexture->setPixel(x, z, Color(normal.x + 0.5, normal.y + 0.5, normal.z + 0.5));
}
}
}

View file

@ -27,7 +27,10 @@
#include "RayCastingResult.h"
#include "OpenGLVegetationImpostor.h"
#include "Texture2D.h"
#include "NoiseNode.h"
#include "FractalNoise.h"
#include "RandomGenerator.h"
#include "NoiseFunctionSimplex.h"
#include <sstream>
#include <iostream>
@ -53,6 +56,18 @@ static void startTestRender(SoftwareCanvasRenderer *renderer, const string &name
startRender(renderer, getFileName(name, iteration).data());
}
static void testNoise() {
NoiseFunctionSimplex noise;
string filename = getFileName("noise_simplex_cache_value");
cout << "Rendering " << filename << "..." << endl;
noise.getValueTexture()->saveToFile(filename);
filename = getFileName("noise_simplex_cache_normal");
cout << "Rendering " << filename << "..." << endl;
noise.getNormalTexture()->saveToFile(filename);
}
static void testGroundShadowQuality() {
Scenery scenery;
RandomGenerator random(5);
@ -345,13 +360,14 @@ static void testOpenGLVegetationImpostor() {
}
void runTestSuite() {
testGroundShadowQuality();
testRasterizationQuality();
testCloudQuality();
testGodRays();
testNearFrustum();
testCloudsNearGround();
testAtmosphereBruneton();
testVegetationModels();
testCloudQuality();
testCloudsNearGround();
testGodRays();
testGroundShadowQuality();
testNearFrustum();
testNoise();
testOpenGLVegetationImpostor();
testRasterizationQuality();
testVegetationModels();
}

View file

@ -10,8 +10,8 @@ vec3 noiseNormal2d(float[4] data, vec2 location, float detail)
while (height > detail)
{
// TODO offsets
// TODO parametrized texture scaling (0.01)
normal += texture(simplexSampler, location * 0.01 * scaling).xyz;
// TODO parametrized texture scaling
normal += texture(simplexSampler, location * scaling / 15.0).xyz - vec3(0.5);
scaling *= step_scaling;
height *= step_height;
}