WIP on clouds testing
This commit is contained in:
parent
dbb780f357
commit
80a6616cd3
5 changed files with 63 additions and 5 deletions
|
@ -559,6 +559,31 @@ static void testCloudModels() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void testCloudsComponents() {
|
||||||
|
Scenery scenery;
|
||||||
|
scenery.autoPreset(2);
|
||||||
|
scenery.getTerrain()->propHeightNoise()->setConfig(0.0);
|
||||||
|
scenery.getCamera()->setLocation(Vector3(0.0, 1.0, 0.0));
|
||||||
|
scenery.getCamera()->setTarget(Vector3(0.0, 2.0, -1.0));
|
||||||
|
scenery.getCamera()->setFov(Maths::PI_2);
|
||||||
|
|
||||||
|
scenery.getClouds()->clear();
|
||||||
|
scenery.getClouds()->addLayer("test");
|
||||||
|
auto layer = scenery.getClouds()->getCloudLayer(0);
|
||||||
|
layer->type = CloudLayerDefinition::STRATOCUMULUS;
|
||||||
|
layer->coverage = 0.7;
|
||||||
|
layer->validate();
|
||||||
|
|
||||||
|
SoftwareCanvasRenderer renderer(&scenery);
|
||||||
|
renderer.setSize(800, 600);
|
||||||
|
renderer.getGodRaysSampler()->setEnabled(false);
|
||||||
|
renderer.setQuality(0.5);
|
||||||
|
|
||||||
|
startTestRender(&renderer, "clouds_component", 0);
|
||||||
|
// TODO Remove detail
|
||||||
|
// TODO Remove shadows
|
||||||
|
}
|
||||||
|
|
||||||
static void testCanvasAliasing() {
|
static void testCanvasAliasing() {
|
||||||
class FakeRasterizer : public OverlayRasterizer {
|
class FakeRasterizer : public OverlayRasterizer {
|
||||||
public:
|
public:
|
||||||
|
@ -590,6 +615,7 @@ void runTestSuite() {
|
||||||
// testCelestialBodies();
|
// testCelestialBodies();
|
||||||
// testNearFrustum();
|
// testNearFrustum();
|
||||||
// testCloudsLighting();
|
// testCloudsLighting();
|
||||||
|
testCloudsComponents();
|
||||||
testCloudModels();
|
testCloudModels();
|
||||||
// testCloudsNearGround();
|
// testCloudsNearGround();
|
||||||
// testVegetationModels();
|
// testVegetationModels();
|
||||||
|
|
|
@ -98,6 +98,18 @@ BaseCloudsModel *CloudsRenderer::getLayerModel(unsigned int layer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CloudsRenderer::setLayerRenderer(unsigned int layer, BaseCloudLayerRenderer *renderer, bool delete_old) {
|
||||||
|
if (layer < layer_renderers.size()) {
|
||||||
|
if (delete_old) {
|
||||||
|
delete layer_renderers[layer];
|
||||||
|
}
|
||||||
|
layer_renderers[layer] = renderer;
|
||||||
|
} else {
|
||||||
|
Logs::warning("Software.Clouds") << "Asked to set an unknown layer model" << layer << endl;
|
||||||
|
delete renderer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CloudsRenderer::setLayerModel(unsigned int layer, BaseCloudsModel *model, bool delete_old) {
|
void CloudsRenderer::setLayerModel(unsigned int layer, BaseCloudsModel *model, bool delete_old) {
|
||||||
if (layer < layer_models.size()) {
|
if (layer < layer_models.size()) {
|
||||||
if (delete_old) {
|
if (delete_old) {
|
||||||
|
|
|
@ -50,7 +50,15 @@ class SOFTWARESHARED_EXPORT CloudsRenderer : public LightFilter {
|
||||||
virtual BaseCloudsModel *getLayerModel(unsigned int layer);
|
virtual BaseCloudsModel *getLayerModel(unsigned int layer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override de default density model for a given layer.
|
* Override the default renderer for a given layer.
|
||||||
|
*
|
||||||
|
* This must be called after each update().
|
||||||
|
* Ownership of the renderer is taken.
|
||||||
|
*/
|
||||||
|
virtual void setLayerRenderer(unsigned int layer, BaseCloudLayerRenderer *renderer, bool delete_old = true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override the default density model for a given layer.
|
||||||
*
|
*
|
||||||
* This must be called after each update().
|
* This must be called after each update().
|
||||||
* Ownership of the model is taken.
|
* Ownership of the model is taken.
|
||||||
|
|
|
@ -30,14 +30,14 @@ BaseCloudsModel::CloudDensityInfo BaseCloudsModel::getDensity(const Vector3 &, d
|
||||||
return {0.0, 1.0};
|
return {0.0, 1.0};
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Vector3 _getPseudoNormal(const BaseCloudsModel *model, const Vector3 &base, const Vector3 &direction, double base_density, double precision) {
|
static inline Vector3 _getPseudoNormal(const BaseCloudsModel *model, const Vector3 &base, const Vector3 &direction,
|
||||||
|
double base_density, double precision) {
|
||||||
double density = model->getDensity(base.add(direction.scale(precision * 10.0)), precision).density;
|
double density = model->getDensity(base.add(direction.scale(precision * 10.0)), precision).density;
|
||||||
double diff = base_density - density;
|
double diff = base_density - density;
|
||||||
return direction.scale(diff > 0.0 ? diff : 0.0);
|
return direction.scale(diff > 0.0 ? diff : 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 BaseCloudsModel::getNormal(const Vector3 &location) const
|
Vector3 BaseCloudsModel::getNormal(const Vector3 &location) const {
|
||||||
{
|
|
||||||
double precision = 0.3;
|
double precision = 0.3;
|
||||||
Vector3 normal = VECTOR_ZERO;
|
Vector3 normal = VECTOR_ZERO;
|
||||||
double base_density = getDensity(location, precision).density;
|
double base_density = getDensity(location, precision).density;
|
||||||
|
@ -47,5 +47,9 @@ Vector3 BaseCloudsModel::getNormal(const Vector3 &location) const
|
||||||
normal = normal.add(_getPseudoNormal(this, location, VECTOR_WEST, base_density, precision));
|
normal = normal.add(_getPseudoNormal(this, location, VECTOR_WEST, base_density, precision));
|
||||||
normal = normal.add(_getPseudoNormal(this, location, VECTOR_NORTH, base_density, precision));
|
normal = normal.add(_getPseudoNormal(this, location, VECTOR_NORTH, base_density, precision));
|
||||||
normal = normal.add(_getPseudoNormal(this, location, VECTOR_SOUTH, base_density, precision));
|
normal = normal.add(_getPseudoNormal(this, location, VECTOR_SOUTH, base_density, precision));
|
||||||
return normal.normalize().scale(Maths::smoothstep(0.0, 1.0, normal.getNorm()));
|
return normal.normalize().scale(Maths::smoothstep(0.0, 0.1, normal.getNorm()));
|
||||||
|
}
|
||||||
|
|
||||||
|
double BaseCloudsModel::getDetailValue(const Vector3 &, double, double) const {
|
||||||
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,14 @@ class SOFTWARESHARED_EXPORT BaseCloudsModel {
|
||||||
*/
|
*/
|
||||||
Vector3 getNormal(const Vector3 &location) const;
|
Vector3 getNormal(const Vector3 &location) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the presence of clouds, at a detail level, given a density factor.
|
||||||
|
*
|
||||||
|
* The detail value is assumed to have a continuous derivative.
|
||||||
|
* To do so, it may return negative-or-zero values for non-presence.
|
||||||
|
*/
|
||||||
|
virtual double getDetailValue(const Vector3 &location, double density, double quality) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CloudLayerDefinition *layer;
|
CloudLayerDefinition *layer;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue