Moon's fractal noise is not saved in scenery

This will make the moon rendering repeatable
This commit is contained in:
Michaël Lemaire 2016-01-22 00:40:42 +01:00
parent c74b6cbdda
commit e6fc00a8ad
4 changed files with 17 additions and 9 deletions

View file

@ -6,6 +6,7 @@
#include "PackStream.h" #include "PackStream.h"
#include "RandomGenerator.h" #include "RandomGenerator.h"
#include "FloatNode.h" #include "FloatNode.h"
#include "NoiseNode.h"
#include "GodRaysDefinition.h" #include "GodRaysDefinition.h"
#include "CelestialBodyDefinition.h" #include "CelestialBodyDefinition.h"
@ -108,6 +109,7 @@ void AtmosphereDefinition::applyPreset(AtmospherePreset preset, RandomGenerator
moon->propRadius()->setValue(1737.4 * Scenery::KM_TO_UNIT); moon->propRadius()->setValue(1737.4 * Scenery::KM_TO_UNIT);
moon->propPhi()->setValue(0.5); moon->propPhi()->setValue(0.5);
moon->propTheta()->setValue(0.3); moon->propTheta()->setValue(0.3);
moon->propNoise()->setConfig(0.4, 0.2, 0.8, 1.1);
model = ATMOSPHERE_MODEL_BRUNETON; model = ATMOSPHERE_MODEL_BRUNETON;

View file

@ -4,6 +4,7 @@
#include "Vector3.h" #include "Vector3.h"
#include "FloatNode.h" #include "FloatNode.h"
#include "Scenery.h" #include "Scenery.h"
#include "NoiseNode.h"
CelestialBodyDefinition::CelestialBodyDefinition(DefinitionNode *parent, const string &name) CelestialBodyDefinition::CelestialBodyDefinition(DefinitionNode *parent, const string &name)
: DefinitionNode(parent, name) { : DefinitionNode(parent, name) {
@ -11,6 +12,7 @@ CelestialBodyDefinition::CelestialBodyDefinition(DefinitionNode *parent, const s
phi = new FloatNode(this, "phi"); phi = new FloatNode(this, "phi");
theta = new FloatNode(this, "theta"); theta = new FloatNode(this, "theta");
radius = new FloatNode(this, "radius"); radius = new FloatNode(this, "radius");
noise = new NoiseNode(this, "noise");
} }
Vector3 CelestialBodyDefinition::getGlobalDirection() const { Vector3 CelestialBodyDefinition::getGlobalDirection() const {

View file

@ -24,6 +24,9 @@ class DEFINITIONSHARED_EXPORT CelestialBodyDefinition : public DefinitionNode {
inline FloatNode *propRadius() const { inline FloatNode *propRadius() const {
return radius; return radius;
} }
inline NoiseNode *propNoise() const {
return noise;
}
/** /**
* Get the normalized direction of the celestial body, from the center of the earth. * Get the normalized direction of the celestial body, from the center of the earth.
@ -48,6 +51,7 @@ class DEFINITIONSHARED_EXPORT CelestialBodyDefinition : public DefinitionNode {
FloatNode *phi; FloatNode *phi;
FloatNode *theta; FloatNode *theta;
FloatNode *radius; FloatNode *radius;
NoiseNode *noise;
}; };
} }
} }

View file

@ -7,16 +7,14 @@
#include "Geometry.h" #include "Geometry.h"
#include "SurfaceMaterial.h" #include "SurfaceMaterial.h"
#include "FloatNode.h" #include "FloatNode.h"
#include "NoiseFunctionSimplex.h" #include "FractalNoise.h"
#include "NoiseNode.h"
class MoonRenderer::pimpl { class MoonRenderer::pimpl {
public: public:
pimpl() : definition(NULL, "moon") { pimpl() : definition(NULL, "moon") {
// TODO Put noise in scenery
noise.setScaling(0.2);
} }
CelestialBodyDefinition definition; CelestialBodyDefinition definition;
NoiseFunctionSimplex noise;
}; };
MoonRenderer::MoonRenderer(CelestialBodyDefinition *moon_node) : DefinitionWatcher("MoonRenderer"), impl(new pimpl()) { MoonRenderer::MoonRenderer(CelestialBodyDefinition *moon_node) : DefinitionWatcher("MoonRenderer"), impl(new pimpl()) {
@ -35,7 +33,7 @@ void MoonRenderer::nodeChanged(const DefinitionNode *, const DefinitionDiff *, c
bool MoonRenderer::getLightsAt(vector<LightComponent> &result, const Vector3 &location) const { bool MoonRenderer::getLightsAt(vector<LightComponent> &result, const Vector3 &location) const {
LightComponent light; LightComponent light;
// TODO Don't add if its contribution is negligible // TODO Don't add if its contribution is negligible or below horizon
// TODO Take moon phase into account // TODO Take moon phase into account
light.color = Color(0.03, 0.03, 0.03); light.color = Color(0.03, 0.03, 0.03);
@ -63,21 +61,23 @@ Color MoonRenderer::getColor(const Vector3 &eye, const Vector3 &direction, Light
auto p1 = nearest.sub(moon_location).normalize(); auto p1 = nearest.sub(moon_location).normalize();
auto coords = p1.toSpherical(); auto coords = p1.toSpherical();
auto noise = impl->definition.propNoise()->getGenerator();
double precision = 0.00001; double precision = 0.00001;
coords.phi += precision; coords.phi += precision;
auto p2 = Vector3(coords); auto p2 = Vector3(coords);
p2 = p2.scale(1.0 - precision * fabs(impl->noise.get3d(0.01, p2.x, p2.y, p2.z))); p2 = p2.scale(1.0 - precision * fabs(noise->get3d(0.01, p2.x, p2.y, p2.z)));
coords.phi -= precision; coords.phi -= precision;
coords.theta += precision; coords.theta += precision;
auto p3 = Vector3(coords); auto p3 = Vector3(coords);
p3 = p3.scale(1.0 - precision * fabs(impl->noise.get3d(0.01, p3.x, p3.y, p3.z))); p3 = p3.scale(1.0 - precision * fabs(noise->get3d(0.01, p3.x, p3.y, p3.z)));
auto normal = p1.getNormal3(p2, p3); auto normal = p1.getNormal3(p2, p3);
double gradient = double gradient = 2.0 + 10.0 * noise->get3d(0.01, 0.3 * p1.x + 12.0, 0.3 * p1.y - 4.8, -0.3 * p1.z + 7.4);
2.3 + 8.0 * impl->noise.get3d(0.01, 0.3 * p1.x + 12.0, 0.3 * p1.y - 4.8, -0.3 * p1.z + 7.4);
SurfaceMaterial material(Color(gradient, gradient, gradient)); SurfaceMaterial material(Color(gradient, gradient, gradient));
material.hardness = 0.3;
auto moon_color = lighting->apply(eye, nearest, normal, material); auto moon_color = lighting->apply(eye, nearest, normal, material);
if (dist <= 0.05) { if (dist <= 0.05) {