Fixed noise scaling in opengl
This commit is contained in:
parent
c81d86d187
commit
02a026116d
3 changed files with 45 additions and 20 deletions
|
@ -476,18 +476,22 @@ double NoiseFunctionSimplex::getBase3d(double x, double y, double z) const {
|
||||||
return noiseSimplexGet3DValue(x, y, z) - 0.5;
|
return noiseSimplexGet3DValue(x, y, z) - 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static constexpr double TEXTURE_SCALING = 15.0;
|
||||||
static Texture2D *_valueTexture = NULL;
|
static Texture2D *_valueTexture = NULL;
|
||||||
|
|
||||||
const Texture2D *NoiseFunctionSimplex::getValueTexture() {
|
const Texture2D *NoiseFunctionSimplex::getValueTexture() {
|
||||||
if (!_valueTexture) {
|
if (!_valueTexture) {
|
||||||
const int width = 1024;
|
const int width = 2048;
|
||||||
const int height = 1024;
|
const int height = 2048;
|
||||||
|
|
||||||
_valueTexture = new Texture2D(width, height);
|
_valueTexture = new Texture2D(width, height);
|
||||||
|
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
for (int z = 0; z < height; z++) {
|
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));
|
_valueTexture->setPixel(x, z, Color(val, val, val));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -500,22 +504,27 @@ static Texture2D *_normalTexture = NULL;
|
||||||
|
|
||||||
const Texture2D *NoiseFunctionSimplex::getNormalTexture() {
|
const Texture2D *NoiseFunctionSimplex::getNormalTexture() {
|
||||||
if (!_normalTexture) {
|
if (!_normalTexture) {
|
||||||
const int width = 1024;
|
const int width = 2048;
|
||||||
const int height = 1024;
|
const int height = 2048;
|
||||||
|
|
||||||
_normalTexture = new Texture2D(width, height);
|
_normalTexture = new Texture2D(width, height);
|
||||||
|
|
||||||
|
double scale = TEXTURE_SCALING;
|
||||||
|
double offset = scale * 0.1;
|
||||||
|
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
for (int z = 0; z < height; z++) {
|
for (int z = 0; z < height; z++) {
|
||||||
// TODO Make texture tileable
|
// TODO Make texture tileable
|
||||||
double vcenter = noiseSimplexGet2DValue(0.01 * to_double(x), 0.01 * to_double(z)) - 0.5;
|
double dx = to_double(x) / to_double(width);
|
||||||
double vsouth = noiseSimplexGet2DValue(0.01 * to_double(x), 0.01 * to_double(z) + 0.001) - 0.5;
|
double dz = to_double(z) / to_double(height);
|
||||||
double veast = noiseSimplexGet2DValue(0.01 * to_double(x) + 0.001, 0.01 * to_double(z)) - 0.5;
|
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 normal = Geometry::getNormalFromTriangle(
|
||||||
Vector3(0.01, veast, 0.0));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,10 @@
|
||||||
#include "RayCastingResult.h"
|
#include "RayCastingResult.h"
|
||||||
#include "OpenGLVegetationImpostor.h"
|
#include "OpenGLVegetationImpostor.h"
|
||||||
#include "Texture2D.h"
|
#include "Texture2D.h"
|
||||||
|
#include "NoiseNode.h"
|
||||||
|
#include "FractalNoise.h"
|
||||||
#include "RandomGenerator.h"
|
#include "RandomGenerator.h"
|
||||||
|
#include "NoiseFunctionSimplex.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -53,6 +56,18 @@ static void startTestRender(SoftwareCanvasRenderer *renderer, const string &name
|
||||||
startRender(renderer, getFileName(name, iteration).data());
|
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() {
|
static void testGroundShadowQuality() {
|
||||||
Scenery scenery;
|
Scenery scenery;
|
||||||
RandomGenerator random(5);
|
RandomGenerator random(5);
|
||||||
|
@ -345,13 +360,14 @@ static void testOpenGLVegetationImpostor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void runTestSuite() {
|
void runTestSuite() {
|
||||||
testGroundShadowQuality();
|
|
||||||
testRasterizationQuality();
|
|
||||||
testCloudQuality();
|
|
||||||
testGodRays();
|
|
||||||
testNearFrustum();
|
|
||||||
testCloudsNearGround();
|
|
||||||
testAtmosphereBruneton();
|
testAtmosphereBruneton();
|
||||||
testVegetationModels();
|
testCloudQuality();
|
||||||
|
testCloudsNearGround();
|
||||||
|
testGodRays();
|
||||||
|
testGroundShadowQuality();
|
||||||
|
testNearFrustum();
|
||||||
|
testNoise();
|
||||||
testOpenGLVegetationImpostor();
|
testOpenGLVegetationImpostor();
|
||||||
|
testRasterizationQuality();
|
||||||
|
testVegetationModels();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ vec3 noiseNormal2d(float[4] data, vec2 location, float detail)
|
||||||
while (height > detail)
|
while (height > detail)
|
||||||
{
|
{
|
||||||
// TODO offsets
|
// TODO offsets
|
||||||
// TODO parametrized texture scaling (0.01)
|
// TODO parametrized texture scaling
|
||||||
normal += texture(simplexSampler, location * 0.01 * scaling).xyz;
|
normal += texture(simplexSampler, location * scaling / 15.0).xyz - vec3(0.5);
|
||||||
scaling *= step_scaling;
|
scaling *= step_scaling;
|
||||||
height *= step_height;
|
height *= step_height;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue