Added /atmosphere/godrays/ definition node

This commit is contained in:
Michaël Lemaire 2015-09-30 01:08:15 +02:00
parent b045b731ad
commit 98e3128c31
12 changed files with 109 additions and 11 deletions

View file

@ -3,10 +3,12 @@
#include "PackStream.h" #include "PackStream.h"
#include "RandomGenerator.h" #include "RandomGenerator.h"
#include "FloatNode.h" #include "FloatNode.h"
#include "GodRaysDefinition.h"
AtmosphereDefinition::AtmosphereDefinition(DefinitionNode* parent): AtmosphereDefinition::AtmosphereDefinition(DefinitionNode* parent):
DefinitionNode(parent, "atmosphere", "atmosphere") DefinitionNode(parent, "atmosphere", "atmosphere")
{ {
godrays = new GodRaysDefinition(this);
daytime = new FloatNode(this, "daytime"); daytime = new FloatNode(this, "daytime");
humidity = new FloatNode(this, "humidity"); humidity = new FloatNode(this, "humidity");
sun_radius = new FloatNode(this, "sun_radius"); sun_radius = new FloatNode(this, "sun_radius");

View file

@ -45,6 +45,7 @@ public:
virtual void copy(DefinitionNode* destination) const override; virtual void copy(DefinitionNode* destination) const override;
inline GodRaysDefinition *childGodRays() const {return godrays;}
inline FloatNode *propDayTime() const {return daytime;} inline FloatNode *propDayTime() const {return daytime;}
inline FloatNode *propHumidity() const {return humidity;} inline FloatNode *propHumidity() const {return humidity;}
inline FloatNode *propSunRadius() const {return sun_radius;} inline FloatNode *propSunRadius() const {return sun_radius;}
@ -78,6 +79,7 @@ public:
std::vector<Star> stars; std::vector<Star> stars;
private: private:
GodRaysDefinition *godrays;
FloatNode *humidity; FloatNode *humidity;
FloatNode *daytime; FloatNode *daytime;
FloatNode *sun_radius; FloatNode *sun_radius;

View file

@ -0,0 +1,12 @@
#include "GodRaysDefinition.h"
#include "FloatNode.h"
GodRaysDefinition::GodRaysDefinition(DefinitionNode *parent):
DefinitionNode(parent, "godrays", "godrays")
{
penetration = new FloatNode(this, "penetration", 0.01);
resistance = new FloatNode(this, "resistance", 0.3);
boost = new FloatNode(this, "boost", 8.0);
}

View file

@ -0,0 +1,29 @@
#ifndef GODRAYSDEFINITION_H
#define GODRAYSDEFINITION_H
#include "definition_global.h"
#include "DefinitionNode.h"
namespace paysages {
namespace definition {
class DEFINITIONSHARED_EXPORT GodRaysDefinition: public DefinitionNode
{
public:
GodRaysDefinition(DefinitionNode *parent);
inline FloatNode *propPenetration() const {return penetration;}
inline FloatNode *propResistance() const {return resistance;}
inline FloatNode *propBoost() const {return boost;}
private:
FloatNode *penetration;
FloatNode *resistance;
FloatNode *boost;
};
}
}
#endif // GODRAYSDEFINITION_H

View file

@ -37,7 +37,8 @@ SOURCES += \
DiffManager.cpp \ DiffManager.cpp \
DefinitionWatcher.cpp \ DefinitionWatcher.cpp \
IntNode.cpp \ IntNode.cpp \
IntDiff.cpp IntDiff.cpp \
GodRaysDefinition.cpp
HEADERS +=\ HEADERS +=\
definition_global.h \ definition_global.h \
@ -64,7 +65,8 @@ HEADERS +=\
DiffManager.h \ DiffManager.h \
DefinitionWatcher.h \ DefinitionWatcher.h \
IntNode.h \ IntNode.h \
IntDiff.h IntDiff.h \
GodRaysDefinition.h
unix:!symbian { unix:!symbian {
maemo5 { maemo5 {

View file

@ -30,6 +30,7 @@ namespace definition {
class CloudsDefinition; class CloudsDefinition;
class CloudLayerDefinition; class CloudLayerDefinition;
class AtmosphereDefinition; class AtmosphereDefinition;
class GodRaysDefinition;
class TexturesDefinition; class TexturesDefinition;
class TextureLayerDefinition; class TextureLayerDefinition;
class TerrainDefinition; class TerrainDefinition;

View file

@ -5,6 +5,7 @@
#include "TerrainDefinition.h" #include "TerrainDefinition.h"
#include "AtmosphereDefinition.h" #include "AtmosphereDefinition.h"
#include "TexturesDefinition.h" #include "TexturesDefinition.h"
#include "GodRaysDefinition.h"
#include "TextureLayerDefinition.h" #include "TextureLayerDefinition.h"
#include "WaterDefinition.h" #include "WaterDefinition.h"
#include "SurfaceMaterial.h" #include "SurfaceMaterial.h"
@ -157,11 +158,37 @@ static void testGodRays()
TestLightFilter filter; TestLightFilter filter;
renderer.getLightingManager()->clearFilters(); renderer.getLightingManager()->clearFilters();
renderer.getLightingManager()->registerFilter(&filter); renderer.getLightingManager()->registerFilter(&filter);
// quality
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
renderer.setQuality((double)i / 5.0); renderer.setQuality((double)i / 5.0);
rasterizer->setQuality(0.2); rasterizer->setQuality(0.2);
startTestRender(&renderer, "god_rays", i); startTestRender(&renderer, "god_rays_quality", i);
}
renderer.setQuality(0.5);
// penetration
for (int i = 0; i < 3; i++)
{
scenery.getAtmosphere()->childGodRays()->propPenetration()->setValue(0.01 + 0.02 * (double)i);
startTestRender(&renderer, "god_rays_penetration", i);
}
// resistance
scenery.getAtmosphere()->childGodRays()->propPenetration()->setValue(0.01);
for (int i = 0; i < 3; i++)
{
scenery.getAtmosphere()->childGodRays()->propResistance()->setValue(0.1 + 0.1 * (double)i);
startTestRender(&renderer, "god_rays_resistance", i);
}
// boost
scenery.getAtmosphere()->childGodRays()->propResistance()->setValue(0.3);
for (int i = 0; i < 3; i++)
{
scenery.getAtmosphere()->childGodRays()->propBoost()->setValue(2.0 + 4.0 * (double)i);
startTestRender(&renderer, "god_rays_boost", i);
} }
} }

View file

@ -5,7 +5,7 @@ GodRaysResult::GodRaysResult(double inside_length, double full_length):
{ {
} }
Color GodRaysResult::apply(const Color &raw, const Color &atmosphered) Color GodRaysResult::apply(const Color &raw, const Color &atmosphered, const GodRaysParams &params)
{ {
if (inside_length == 0.0) if (inside_length == 0.0)
{ {
@ -14,14 +14,16 @@ Color GodRaysResult::apply(const Color &raw, const Color &atmosphered)
else if (inside_length < full_length) else if (inside_length < full_length)
{ {
double diff = full_length - inside_length; double diff = full_length - inside_length;
double factor = 1.0 - 0.01 * diff; double factor = 1.0 - params.penetration * diff;
if (factor < 0.3) double minimum = params.resistance;
double complement = 1.0 - minimum;
if (factor < minimum)
{ {
factor = 0.3; factor = minimum;
} }
else else
{ {
factor = pow((factor - 0.3) / 0.7, 8.0) * 0.7 + 0.3; factor = pow((factor - minimum) / complement, params.boost) * complement + minimum;
} }
return Color(raw.r + (atmosphered.r - raw.r) * factor, return Color(raw.r + (atmosphered.r - raw.r) * factor,

View file

@ -13,6 +13,13 @@ namespace software {
*/ */
class SOFTWARESHARED_EXPORT GodRaysResult class SOFTWARESHARED_EXPORT GodRaysResult
{ {
public:
typedef struct {
double penetration;
double resistance;
double boost;
} GodRaysParams;
public: public:
GodRaysResult() = default; GodRaysResult() = default;
GodRaysResult(double inside_length, double full_length); GodRaysResult(double inside_length, double full_length);
@ -20,7 +27,7 @@ public:
/** /**
* Apply the result on a base color. * Apply the result on a base color.
*/ */
Color apply(const Color &raw, const Color &atmosphered); Color apply(const Color &raw, const Color &atmosphered, const GodRaysParams &params);
private: private:
double inside_length; double inside_length;

View file

@ -1,10 +1,13 @@
#include "GodRaysSampler.h" #include "GodRaysSampler.h"
#include "GodRaysDefinition.h"
#include "AtmosphereDefinition.h"
#include "SoftwareRenderer.h" #include "SoftwareRenderer.h"
#include "Vector3.h" #include "Vector3.h"
#include "SpaceSegment.h" #include "SpaceSegment.h"
#include "GodRaysResult.h" #include "GodRaysResult.h"
#include "LightingManager.h" #include "LightingManager.h"
#include "FloatNode.h"
#include "LightStatus.h" #include "LightStatus.h"
#include "Scenery.h" #include "Scenery.h"
#include "TerrainDefinition.h" #include "TerrainDefinition.h"
@ -16,6 +19,7 @@ GodRaysSampler::GodRaysSampler()
{ {
enabled = true; enabled = true;
bounds = new SpaceSegment(); bounds = new SpaceSegment();
definition = new GodRaysDefinition(NULL);
camera_location = new Vector3(0, 0, 0); camera_location = new Vector3(0, 0, 0);
lighting = NULL; lighting = NULL;
low_altitude = -1.0; low_altitude = -1.0;
@ -28,6 +32,7 @@ GodRaysSampler::GodRaysSampler()
GodRaysSampler::~GodRaysSampler() GodRaysSampler::~GodRaysSampler()
{ {
delete definition;
delete bounds; delete bounds;
delete camera_location; delete camera_location;
delete[] data; delete[] data;
@ -38,6 +43,7 @@ void GodRaysSampler::prepare(SoftwareRenderer *renderer)
setCameraLocation(renderer->getCameraLocation(VECTOR_ZERO)); setCameraLocation(renderer->getCameraLocation(VECTOR_ZERO));
setLighting(renderer->getLightingManager()); setLighting(renderer->getLightingManager());
setAltitudes(renderer->getScenery()->getTerrain()->getHeightInfo().min_height, renderer->getCloudsRenderer()->getHighestAltitude()); setAltitudes(renderer->getScenery()->getTerrain()->getHeightInfo().min_height, renderer->getCloudsRenderer()->getHighestAltitude());
renderer->getScenery()->getAtmosphere()->childGodRays()->copy(definition);
reset(); reset();
} }
@ -178,7 +184,13 @@ Color GodRaysSampler::apply(const Color &raw, const Color &atmosphered, const Ve
if (enabled) if (enabled)
{ {
GodRaysResult result = getResult(SpaceSegment(*camera_location, location)); GodRaysResult result = getResult(SpaceSegment(*camera_location, location));
return result.apply(raw, atmosphered);
GodRaysResult::GodRaysParams params;
params.penetration = definition->propPenetration()->getValue();
params.resistance = definition->propResistance()->getValue();
params.boost = definition->propBoost()->getValue();
return result.apply(raw, atmosphered, params);
} }
else else
{ {

View file

@ -99,6 +99,8 @@ private:
bool enabled; bool enabled;
SpaceSegment *bounds; SpaceSegment *bounds;
GodRaysDefinition *definition;
double sampling_step; double sampling_step;
double max_length; double max_length;
double walk_step; double walk_step;

View file

@ -95,7 +95,7 @@ const Color NightSky::getColor(double altitude, const Vector3 &direction)
} }
bool NightSky::getLightsAt(std::vector<LightComponent> &result, const Vector3 &location) const bool NightSky::getLightsAt(std::vector<LightComponent> &result, const Vector3 &) const
{ {
LightComponent moon, sky; LightComponent moon, sky;